[英]Extract the values from a specific key in a json file
I have a data which is this(I extract this from a json file): 我有一个数据,这是(我从一个json文件中提取):
{
data1:[
"Hello",
"How are you",
"Are u alright"
],
data2:[ "Hello",
"How are you",
"Are u alright",
"HOwdy!"
]
}
There is this thing that i need either the data1 values or data2 values ie, array as a whole based on the input,,if i enter the input as data1 then data1 array should be stored in another value and vice versa.I tried using Object.keys() and filter functions and can't get the array as a whole. 有一件事情我需要data1值或data2值,即基于输入的数组作为整体,如果我将输入作为data1输入,则data1数组应该存储在另一个值中,反之亦然。我尝试使用Object .keys()和过滤器函数,无法整体获取数组。
Input: 输入:
data1
Output: 输出:
[
"Hello",
"How are you",
"Are u alright"
]
You can get the values using brackets notation like 您可以使用方括号表示法获取值,例如
const obj = { data1:[ "Hello", "How are you", "Are u alright" ], data2:[ "Hello", "How are you", "Are u alright", "HOwdy!" ] } const input1 = 'data1'; const input2 = 'data1'; console.log(obj[input1], obj[input2]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.