JSON/[removed] return which array object contains a certain property

后端 未结 1 1104
南旧
南旧 2021-01-26 09:06

Given a JSON object such as this:

{
  \"something\": {
    \"terms\": [
      {
        \"span\": [
          15,
          16
        ],
        \"value\": \":\         


        
相关标签:
1条回答
  • 2021-01-26 09:52

    Use Array.prototype.filter:

    var numberValue, list = parsed.something.terms.filter(function(a){
      return a.label==='number';
    });
    numberValue = list.length ? list[0].value : -1;
    
    0 讨论(0)
提交回复
热议问题