Remove Object from Array using JavaScript

前端 未结 29 2703
南笙
南笙 2020-11-22 10:24

How can I remove an object from an array? I wish to remove the object that includes name Kristian from someArray. For example:

som         


        
29条回答
  •  庸人自扰
    2020-11-22 10:49

    I guess the answers are very branched and knotted.

    You can use the following path to remove an array object that matches the object given in the modern JavaScript jargon.

    
    coordinates = [
        { lat: 36.779098444109145, lng: 34.57202827508546 },
        { lat: 36.778754712956506, lng: 34.56898128564454 },
        { lat: 36.777414146732426, lng: 34.57179224069215 }
    ];
    
    coordinate = { lat: 36.779098444109145, lng: 34.57202827508546 };
    
    removeCoordinate(coordinate: Coordinate): Coordinate {
        const found = this.coordinates.find((coordinate) => coordinate == coordinate);
        if (found) {
          this.coordinates.splice(found, 1);
        }
        return coordinate;
      }
    

提交回复
热议问题