I have this set
var data = [
{"outlet_name":"Easy Lane Supermart","20130102_20130108":"0"},
{"outlet_name":"Eunilaine Foodmart Kalayaan","20130102_20130108":"0"},
{"outlet_name":"PUREGOLD PRICE CLUB, INC - VISAYAS","20130102_20130108":"0"}
];
$.each(data, function (i, item) {
$.each(item, function (k,v) {
$('#result').append(k,v);
});
});
How can I make it only view all the values of outlet_name
without using the item.outlet_name?
You can acces items in arrays at given position by their index. In javascript indexes of arrays are starting with 0: myArray[0] . To access the property of the returned object just use dot-notation: myArray[0].
Use array. forEach() method to traverse every object of the array. For each object use delete obj. property to delete the certain object element from array of objects.
Just as object properties can store values of any primitive data type (as well as an array or another object), so too can arrays consist of strings, numbers, booleans, objects, or even other arrays.
$.each(data, function (i, item) {
console.log(item.outlet_name);
});
Or without jQuery:
for (var i=0;i<data.length;i+=1) {
console.log(data[i].outlet_name);
}
Ok, if you want to iterate over each object you can write:
$.each(data, function (i, item) {
console.log("Values in object " + i + ":");
$.each(item, function(key, value) {
console.log(key + " = " + value);
});
});
This will provide exact answer...
var data = [
{"outlet_name":"Easy Lane Supermart","20130102_20130108":"0"},
{"outlet_name":"Eunilaine Foodmart Kalayaan","20130102_20130108":"0"},
{"outlet_name":"PUREGOLD PRICE CLUB, INC - VISAYAS","20130102_20130108":"0"}
];
for(i=0;i<data.length;i++){
for(var x in data[i]){
console.log(x + " => " + data[i][x]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With