I have an array imported via AJAX. I want to create a new array based on the original one and scan through the whole new array in order to clean the value WHATEVER the key associated to it.
The imported dataset looks like this:
[
{id:"1", color:"red_blue", height:"100_200" },
{id:"2", color:"green", height:"100_20" },
{id:"3", color:"orange_yellow", height:"50" }
]
And the jQuery process looks like this
dataSet = JSON.parse(response);
// create a new array based on the imported array
var row = 0;
$.each(dataSet, function(key, value) {
cleanDataSet.push(dataSet[row]);
row++;
});
// clean the new array
var row = 0;
// Go through each row of the array
$.each(cleanDataSet, function(key, value) {
// Go through each key and value of this array
$.each(cleanDataSet[row], function(key, value) {
var myVariable = thisValueWhateverTheKey.split('_');
// if a split is detected in the value
if (myVariable[1]) {
// Update the value
thisValueWhateverTheKey = myVariable[0];
}
row++;
});
});
console.log(cleanDataSet)
The "thisValueWhateverTheKey" part is obviously the one I can't figure out.
It's easy when I target the values of a specific key (I would use "value.nameofmykey" but not that much when I target any value of any key. "value" alone won't work.