Tengo una matriz de objetos con la siguiente estructura:
const timeOptions = [ { key: "all", value: "all", text: "All" }, { key: "month", value: "month", text: "Month" }, { key: "year", value: "year", text: "Year" } ]; Estoy creando un nuevo objeto con este timeOptions siendo un valor de un campo en él. Cómo eliminar el objeto con la tecla "todos" in-place mientras se crea el objeto en sí
const values = { timeVal: { field: "timestamp", label: "Timestamp", options: timeOptions } };Código que probé
const values = { timeVal: { field: "timestamp", label: "Timestamp", options: timeOptions.forEach((k) => delete k["key"] === "all") } };Usando Array#filter :
options: timeOptions.filter(({ key }) => key !== 'all')Si te entiendo bien, necesitas filtro .
const values = { timeVal: { field: "timestamp", label: "Timestamp", options: timeOptions.filter((k) => k["key"] !== "all") }};
Esto copiará todo excepto el que tiene la tecla "todos"