gpt4 book ai didi

javascript/json .length 对于长度为 3 的数组返回 1

转载 作者:行者123 更新时间:2023-12-03 11:41:16 25 4
gpt4 key购买 nike

我有以下 JavaScript:

var emails_array = ["[\"theiremail1\",\"theiremail2\",\"theiremail3\"]"];
var emails_array_length = emails_array.length;
alert("emails array: " + emails_array + "emails array length: " + emails_array_length);

此代码的结果显示的警报是:

emails array: ["theiremail1","theiremail2","theiremail3"]emails array length: 1

为什么不返回 3?

最佳答案

这是一个只有一项的数组:

var emails_array = [
"[\"theiremail1\",\"theiremail2\",\"theiremail3\"]"
];

您可能追求的目标:

var emails_array = JSON.parse(["[\"theiremail1\",\"theiremail2\",\"theiremail3\"]"]);

http://jsfiddle.net/wtLo7h7s/

关于javascript/json .length 对于长度为 3 的数组返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26262083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com