These are the 7 attributes of the object, but the 6th 4.1.85 will change. In this way, how can we get the 6th attribute without relying on the attribute name? . . .
Using the object.key(object) method, the returned results are sorted, so it is still not fixed every time I retrieve it! !
習慣沉默2017-06-12 09:33:21
The attribute name should be unchanged, right? What should be obtained is the corresponding value?
曾经蜡笔没有小新2017-06-12 09:33:21
Then you use the elimination method, loop through all the attributes of the current object, exclude the inherent attributes, and then get the unknown attribute, provided that your other attribute names are fixed.
学习ing2017-06-12 09:33:21
The default key is fixed, so it can be traversed through $.each(), as follows:
var object = {
name : "张三",
age : 22,
tell : 1234565678,
height : 180,
num : Math.floor(Math.random()*10+1),
color : "red"
}
$.each(object,function(key,val){
if(val === object.num ){
console.log(val);
}
})
Even if the object is out of order, it can be traversed through $.each(), and then judged by conditions. Hope it will be adopted.
三叔2017-06-12 09:33:21
Use Object.entries(obj)
var car = {type:"Fiat", model:"500", color:"white"};
console.log(Object.entries(car));
The output is:
type,Fiat,model,500,color,white
The matching order can be guaranteed.
In addition, the properties of Object are not guaranteed to be ordered (different from guaranteed to be unordered)