I have an array of column indexes that looks like, for example, [2, 4, 5] and an object with string value keys ranging from "0" through "6".
I want to create a new array containing all elements from my original object except those with keys matching any value in my column index array. This is how I'm doing it currently but I'm not happy with it:
const convertObjectToArray = (columnIndexes, rowObject) => {
return Object.keys(rowObject).map(key => {
let rowValue = '';
if (columnIndexes.indexOf(parseInt(key)) === -1) {
rowValue = rowObject['' + key];
}
return rowValue;
});
};
Perhaps there is a very simple, straightforward way of doing this and I'm just missing it?
Object.keys(obj).filter( k => columnIndices.indexOf(parseInt(k)) >= 0).map( k => obj[k])ifwith a ternary expression:return columnIndices.indexOf(parseInt(k)) >= 0 ? '' : obj[k].