javascript erase vector element code example

Example 1: remove a particular element from array

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

Example 2: how to append an element to an array in cpp

std::vector<std::string> x = {"a", "b", "c"};
x.push_back("d");

Example 3: c++ remove element from vector

vector.erase(position) // remove certain position
// or
vector.erase(left,right) // remove positions within range

Tags:

Cpp Example