Yes, I have done my research and found out about this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split or the possible duplicate people could refer to: How to split comma separated string using JavaScript?
however my question now is: When I fetch my syllables
(I'll be right back on what that is) I end up with commas between each word I have. I would like to escape these commas so the syllables
go into their own input field instead of becoming one string in one input field.
This is how my loop looks like right now:
$(document).ready(function () {
$.getJSON('json_files/jsonData_' + ID + '.json', function(json) {
//Fetches the correct exercise title from the database and places it inside the header
var exercisetitle = json.main_object.getExerciseTitle;
$("#getExerciseTitle").val(exercisetitle);
//loops through the words and fetches them back to the CMS side.
var exercise = json.main_object.main_object.exercises;
$.map(exercise, function(exercise, i) {
$("#addOpdracht").click();
$(".exerciseGetWordInput_" + i).val(exercise.word) // starts with 0
console.log(exercise.syllables);
$(".sylll" + i).val(exercise.syllables)
});
});
});
however when I use this loop I end up with the words in one input field with commas in between and therefore it fetches back all the words in one input field.
How my JSON looks like:
{
"main_object": {
"id": "new",
"getExerciseTitle": "TestToConfirmMoreWords",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
"title": "TestToConfirmMoreWords",
"language": "nl_NL",
"exercises": [
{
"word": "HACCP",
"syllables": [
"1",
"2",
"",
""
]
},
{
"word": "HACCP-normen",
"syllables": [
"123",
"123",
"123",
""
]
}
]
},
"dataType": "json"
}
}
And here is a picture so it's easier to visualize:
as you can see it puts "1,2,," in one input field instead of 2 input fields and the 2 last input fields empty. It also just stacks "123,123,123," underneath it in one input field, instead of placing it in the right exercise field with each in their respective input field. The last one should again, be empty since that's an "empty" string.
Is it me who's looking in the wrong direction (e.a looking at the split
function while that won't solve the issue) or is it something else that I am missing out on?