0

前任:

{
  "123": [
     ...stuff
  ]
}

如何在 jquery 中调用“123”而不返回错误?

我试过了:

$.getJSON('insert-url-here').then(function (data) { console.log(data.123.length) }

但它不起作用。

4

1 回答 1

0

使用方括号表示法:

const data = {
  "123": [1, 2, 3]
}

console.log(data[123].length);

或者因为它在技术上是一个字符串:

const data = {
  "123": [1, 2, 3]
}

console.log(data["123"].length);

于 2019-05-03T23:41:30.823 回答