简体   繁体   English

如何使用 LODASH 从数组中删除元素并降低排名

[英]How to remove an element from array and decrease the rank using LODASH

I am working in Angular2.我在 Angular2 工作。 I have an array like below:我有一个如下所示的数组:

rank   |   book name
---------------------
  1    |   maths
  2    |   physics
  3    |   english
  4    |   hindi

Now i want to remove an Item, Let i am removing rank 1 and book name is maths现在我想删除一个项目,让我删除排名1 ,书名是数学

Which must be remove the maths row and adjust the ranks after that element.必须删除数学行并在该元素之后调整排名。 I want the result will be like this:我希望结果是这样的:

rank   |   book name
---------------------
  1    |   physics
  2    |   english
  3    |   hindi

What to do Remove and also decrease the rank simultaneously using lodash in angular2?在 angular2 中使用 lodash 删除并同时降低排名?

Without lodash没有 lodash

var array = ["Maths", "Physics", "English", "Hindi"];
const result = array.filter(array => array !== "Maths");
var object = {};
var i = 0;
for (rank in result) {
i++
object[i] = result[rank]
}
console.log(object);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM