
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.99 KB | hits: 15 | expires: Never
javascript - best way to convert values of object or array
var legend = {
"html": "html5",
"css2": "css3",
"javascript": "jquery"
}
var old_array = new Array("html", "css2", "javascript");
var new_array = [];
max = old_array.length;
// loop through values in original array
for(i=0;i<max;i++){
for(var val in legend){
// looping through values in legend. If match, convert
if(old_array[i] === val){
new_array[i] = legend[val];
}
}
}
console.log(new_array);
document.write(new_array);
var legend = {
"html": "html5",
"css2": "css3",
"javascript": "jquery"
}
var old_array = new Array("html", "css2", "javascript");
var new_array = [];
max = old_array.length;
// loop through values in original array
for(var i=0;i<max;i++){
// see if array value is a key in the legend object
if ([old_array[i] in legend) {
new_array.push(legend[old_array[i]]);
}
}
console.log(new_array);
document.write(new_array);