如何更改數組物件屬性值javascript
<p>我有一個陣列物件和一個陣列。該數組中的哪些值與數組物件中的值相符需要更改狀態(如 true)。 </p>
<p><code>arrObj</code> 輸出應如下圖所示:</p>
<pre class="brush:php;toolbar:false;">[
{ name: "Test1", status: true },
{ name: "Test2", status: false },
{ name: "Test3", status: true }
]</pre>
<p>示範:https://stackblitz.com/edit/github-7plax5-mu3l6a?file=src/app/app.component.ts</p>
<p>
<pre class="snippet-code-js lang-js prettyprint-override"><code>let arrObj = [{
name: "Test1",
status: true
},
{
name: "Test2",
status: true
},
{
name: "Test3",
status: true
}
]
let arr = ["Test1", "Test3"];
for (k of arr) {
if (arrObj.name == k) {
arrObj.status = true;
}
}
console.log(arrObj);</code></pre>
</p>