Click here to Skip to main content
14,929,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var object='{"name":"PHP Tutorial","Description":"Expert in web technology"}';
Posted
Comments
Mehdi Gholam 30-Jan-16 9:53am
   
There is no array in that json.
Sergey Alexandrovich Kryukov 30-Jan-16 22:05pm
   
You are right, in a way; and I credited your comment in my answer, but things are not as simple.
In fact, not every JavaScript object is a JavaScript array, but every object (of the type 'object') is an associative array. A JavaScript array is also a JavaScript object, only specialized, and it can mix different kinds of properties. It has the property length. This typing and terminology is very confusing, as many thins in JavaScript.

Please see Solution 1.

—SA

1 solution

As Mehdi said in his comment to the question, this is not an array, but is a JavaScript object, which comes with key-value pairs, key being a property name, and value — the respective property value. But any JavaScript object can be considered as an associative array. Such array is not the same as JavaScript array, which is a specialized object (essentially with the property length; oriented to the use of integers used as property names, but any kinds of properties can be mixed in the same object).

That said, you have to learn at least main principles of JavaScript Please see:
JavaScript — Wikipedia, the free encyclopedia[^],
Associative array — Wikipedia, the free encyclopedia[^].

About arrays objects as specialized JavaScript objects, please read
Array — JavaScript | MDN[^].

Finally, this is how you parse JSON string into an object:
JSON.parse() — JavaScript | MDN[^],
see also: JSON — JavaScript | MDN[^].

—SA
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900