store values in json object javascript code example
Example 1: key value json javascript
var jsonArray = '{"required":1, "minlength":2}'
var jsonParsedArray = JSON.parse(jsonArray);
for (key in jsonParsedArray) {
if (jsonParsedArray.hasOwnProperty(key)) {
console.log("%c "+key + " = " + jsonParsedArray[key],"color:cyan");
}
}
Example 2: javascript create json object from array
var array = ['a', 1, 'b', 2, 'c', 3],
object = {},
i
for (var i = 0; i < array.length; i += 2) {
object[array[i]] = array[i + 1];
}
console.log(object);