[英]Object.keys not printing properly
I am trying to get only keys from the object, but I am getting 0 1 2 3 as output.我试图只从 object 获取密钥,但我得到 0 1 2 3 作为 output。
Below is my code下面是我的代码
data = {"property" : "{\"animalID\": \"12345\", \"animalNumber\" : \"789\", \"type\" : \"mamal\"}"}
onCLick() {
const dataOne = (JSON.parse(JSON.stringify(this.data)));
console.log("data", Object.keys(dataOne.property));
}
Below is the current output, which is wrong.下面是当前的output,是错误的。
data (61) ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60']
数据(61)['0','1','2','3','4','5','6','7','8','9','10',' 11'、'12'、'13'、'14'、'15'、'16'、'17'、'18'、'19'、'20'、'21'、'22'、'23' , '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', ' 36'、'37'、'38'、'39'、'40'、'41'、'42'、'43'、'44'、'45'、'46'、'47'、'48' , '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60']
Trying to achieve something like this试图实现这样的目标
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
You need to parse the JSON string to object
as below:您需要将 JSON 字符串解析为
object
,如下所示:
data = {"property": "{\"animalID\": \"12345\", \"animalNumber\": \"789\", \"type\": \"mamal\"}"}; const dataOne = JSON.parse(data["property"]); console.log("data", Object.keys(dataOne));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.