I get id and category name from mysql database.
When I am alerting a result, I get:
[{"id":"197","category":"Damskie"},"id":"198","category":"M\u0119skie"}]
(Is this object?)
How can I print a result like this:
Damskie
M\u0119skie
M\u0119ski - has bad encoding. It should be Męskie. How can I change this?
map can be used like this: var array = [...]; var newHTML = $. map(array, function(value) { return('<span>' + value + '</span>'); }); $(". element").
var arr = ["Mahesh", "Praveen", "DJ", "Jignesh", "Vulpes"]; // Define jquery each loop to get value of array. $. each(arr, function (index, value)
each(), which is used to iterate, exclusively, over a jQuery object. The $. each() function can be used to iterate over any collection, whether it is an object or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.
JQuery | map() Method This map() Method in jQuery is used to translate all items in an array or object to new array of items. Syntax: jQuery.map( array/object, callback )
var arrofobject = [{"id":"197","category":"Damskie"},{"id":"198","category":"M\u0119skie"}];
$.each(arrofobject, function(index, val) {
console.log(val.category);
});
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