我对前端开发很陌生。我用的是反应。
我的问题是:如何提取数组中的对象值?
myArr = [[{a: 1, b: 2}], [{a: 1, b:2}], [{a: 1, b:2}]]
// I want to extract only the values of b and make them into array
// my asnwer should look like this:
// [2,2,2]我的方法:
const [answerArr, setAnswerArr] = useState([]);
useEffect(() => {
const extractCode = () => {
const res = myArr.map((item)=>{
????
})
};
extractCode();
}, [codeArr]);我试过用地图method...but我很挣扎.如果你能帮我,我会学到这么多!
发布于 2022-08-24 11:30:41
您的代码应该如下所示
const res = myArr.map(item => item[0].b)https://stackoverflow.com/questions/73472307
复制相似问题