Can I utilize array.map
in TypeScript to apply a function with the parameter being the key of an object within an array? I have an array containing objects which have keys 'min' and 'max'. I am looking to use something like
someArrayFunction(array.map(func1(key), array.map()))
to compare the values of each key in the object array.
const allVariables: any[] = [
[ { name: 'a', value:{min: 1, max: 2}, expect: {min: 1, max: 2}}, { name: 'b', value: {min: 11, max: 22}, expect: {min:11, max: 22} }],
[ { name: 'a1',value:{min: 1, max: 2}, expect: {min: 1, max: 2}}, {name: 'b1', value: {min: 11, max: 22}, expect: {min:11, max: 22} }],
[ { name: 'a2',value:{min: 1, max: 2}, expect: {min: 1, max: 2}}, {name: 'b2', value: {min: 11, max: 22}, expect: {min:11, max: 22} }],
];
allVariables.forEach(obj => {
Object.keys(obj).forEach((key) => {
// someArrayFunction(someFunc(obj.name, key), obj.value[key])
// comparing value.min === expect.min for name a
// comparing value.min === expect.min for name b
// comparing value.min === expect.min for name a1
// comparing value.min === expect.min for name b1
// comparing value.min === expect.min for name c1
})
})
// someArrayFunction(parameter: string[], v: number){
// do something with parameter and v...
// }