I want to remove Double Quote from string "Hello"
word.
我想从字符串“Hello”字中删除Double Quote。
I have array var ary = ['a', 'b' , 'c']
Now when I take value from array it's return into string like if I use ary[0] = "a"
but I want in value like a
.
我有数组var ary = ['a','b','c']现在当我从数组中获取值时,它会返回到字符串,就像我使用ary [0] =“a”但我想要的值就像a。
Because I have One JSON file That contains
因为我有一个包含的JSON文件
{
"a":{
"name" : "Emma"
},
"b":{
"name" : "Harry"
},
"c":{
"name" : "Jonny"
}
}
I want value from Here using Those array like ary[0].name = Emma
我想从这里使用那些数组像ary [0] .name = Emma
NOTE : I used str.replace(/\"/gi,""); && str.replace(/"/gi,"");
If any Other Idea How can I get than please Replay ASAP.
注意:我使用了str.replace(/ \“/ gi,”“); && str.replace(/”/ gi,“”);如果有任何其他想法我怎么能得到比请尽快重播。
1 个解决方案
#1
If I understood your requirement correctly, you can just use bracket notation like obj['a'].name
如果我正确理解了你的要求,你可以使用像obj ['a']这样的括号表示法
var obj = {
a: {
"name": "Emma"
},
b: {
"name": "Harry"
},
c: {
"name": "Jonny"
}
};
var ary = ['a', 'b', 'c']
for (var i = 0; i < ary.length; i++) {
console.log(obj[ary[i]].name)
}
Here you pass the property key as a string to the bracket notation and it will return the value
在这里,您将属性键作为字符串传递给括号表示法,它将返回值
#1
If I understood your requirement correctly, you can just use bracket notation like obj['a'].name
如果我正确理解了你的要求,你可以使用像obj ['a']这样的括号表示法
var obj = {
a: {
"name": "Emma"
},
b: {
"name": "Harry"
},
c: {
"name": "Jonny"
}
};
var ary = ['a', 'b', 'c']
for (var i = 0; i < ary.length; i++) {
console.log(obj[ary[i]].name)
}
Here you pass the property key as a string to the bracket notation and it will return the value
在这里,您将属性键作为字符串传递给括号表示法,它将返回值