Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print jquery object/array

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?)

  1. How can I print a result like this:

    Damskie

    M\u0119skie

  2. M\u0119ski - has bad encoding. It should be Męskie. How can I change this?

like image 740
Sadu Avatar asked Apr 19 '12 15:04

Sadu


People also ask

How to display array jQuery?

map can be used like this: var array = [...]; var newHTML = $. map(array, function(value) { return('<span>' + value + '</span>'); }); $(". element").

How to get array data in jQuery?

var arr = ["Mahesh", "Praveen", "DJ", "Jignesh", "Vulpes"]; // Define jquery each loop to get value of array. $. each(arr, function (index, value)

How to iterate array in jQuery?

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.

What is map() in jQuery?

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 )


1 Answers

var arrofobject = [{"id":"197","category":"Damskie"},{"id":"198","category":"M\u0119skie"}];

$.each(arrofobject, function(index, val) {
    console.log(val.category);
});
like image 119
thecodeparadox Avatar answered Sep 29 '22 19:09

thecodeparadox