I have a JSON:
var xx = {'name':'alx','age':12};
Now I can read the value of name, which is "alx" as xx [0] .name, but how do I get the value of the name itself? By this I mean, how can I get the key at runtime?
for (i in xx) { if (xx[i] == "alx") { // i is the key } }
modified code (from Victor), given that you can search for any other possible line
var search_object = "string_to_look_for"; for (i in xx) { if (xx[i] == search_object) { // i is the key alert(i+" is the key!!!"); // alert, to make clear which one } }
Javascript. Google :
Read this page http://www.quirksmode.org/js/associative.html
and especially this section http://www.quirksmode.org/js/associative.html#link5
Source: https://habr.com/ru/post/1747827/More articles:Using SVN alone or in small workgroups - workflow approach? - version-controlHow to set date and time bindings using JAXWS and APT? - javaC # How to redirect assembly using application configuration file - c #Как загрузить файл свойств, помещенный в путь к классам из JSP? - javaShortcut for jQuery update - jqueryWpf datagrid row not updating when updating bound collection? - wpf$ _SERVER ['HTTP_REFERER'] vs Request.ServerVariables( "HTTP_REFERER" ) - phpSending on receipt in C - cEncryption: TCB (Tweaked CodeBook) algorithm - what is it? - encryptionCall a function by its name specified in the java - javaAll Articles