I was trying to set a boolean property for every object of an array.
import { Component, OnInit } from "@angular/core";
import * as _ from "lodash";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
title = "CodeSandbox";
colors: {hex: string, used: boolean}[] = [
{hex: "#ff0000", used: true},
{hex: "#00ff00", used: true},
{hex: "#0000ff", used: true}
]
ngOnInit() {
_.forEach(this.colors, c => c.used = false);
console.log(this.colors);
}
}
Apparently only the first object is affected. This is the output.
0: Object
hex: "#ff0000"
used: false
1: Object
hex: "#00ff00"
used: true
2: Object
hex: "#0000ff"
used: true
Here is the sandbox: https://codesandbox.io/s/strange-water-p19ihj?file=/src/app/app.component.ts
It works with _.map and with native forEach. Am I missing something or is it a bug?