Javascript数组问题 在数组中解析Int字符串

问题描述 投票:0回答:1

我找了7天,在所有的论坛上。我找了7天,在所有的论坛上都找过了,很难,也许这个案例比较特殊。(谢谢你的帮助... )

    const ARRAY1 = [



      { Ville:  'Anse-Bertrand (97121)' , taux: 0.6393  },
      { Ville: 'Saint-Louis (97421)', taux: 0.6359  },
      { Ville:  'La Haute-Beaume (05140)', taux:    0.5900  },
      { Ville:  'Fontanès-de-Sault (11140)', taux:  0.5791  },
      { Ville:  'Chambord (41250)', taux:   0.5658  }


    ]


    const ARRAY2 = (ARRAY1.Ville.replace(/\d/g, ""))
    //i want to replace all characteres of all (Ville) by "_". To just have the postal codes.

    var KeySearched = "05140"



    function isTaux (answer) {
      return answer.Ville ==KeySearched ;
    }

    console.log(ARRAY2.find(isTaux).taux);
arrays string numbers const parseint
1个回答
0
投票

你想要这样的东西吗?

const ARRAY2 = [
  { Ville:  'Anse-Bertrand (97121)' , taux: 0.6393  },
  { Ville: 'Saint-Louis (97421)', taux: 0.6359  },
  { Ville:  'La Haute-Beaume (05140)', taux:    0.5900  },
  { Ville:  'Fontanès-de-Sault (11140)', taux:  0.5791  },
  { Ville:  'Chambord (41250)', taux:   0.5658  }
]


const NewArr = ARRAY2.map(function(a, b) {
    a.Ville = a.Ville.replace(/[\D]/g, "")
    return a
})

console.log(NewArr)
© www.soinside.com 2019 - 2024. All rights reserved.