I have an array with multiple objects inside like below.
[{ DishId: 40, DishName: "Mango", TimeSpan: 98},
{ DishId: 41, DishName: "Banana", TimeSpan: 99},
{ DishId: 42, DishName: "Orange", TimeSpan: 100}]
And i wanted to extract DishId and DishName from it and create another array of objects like below : Expected Output:
[{ DishId: 40, DishName: "Mango"},
{ DishId: 41, DishName: "Banana"},
{ DishId: 42, DishName: "Orange"}]
I am doing below
allDishes =
[{ DishId: 40, DishName: "Mango", TimeSpan: 98},
{ DishId: 41, DishName: "Banana", TimeSpan: 99},
{ DishId: 42, DishName: "Orange", TimeSpan: 100}];
var dishes = {};
var dishesArray = [];
for(i = 0; i < allDishes.length; i++){
dishes.DishId= allDishes[i].DishId;
dishes.DishName = allDishes[i].DishName;
dishesArray.push(dishes);
}
It is giving same repeated objects where as i am wanting all different object as i shown in example above
[ { DishId: 42, DishName: 'Orange' },
{ DishId: 42, DishName: 'Orange' },
{ DishId: 42, DishName: 'Orange' }]