Pousser vers un tableau
array = ["hello"]
array.push("world");
console.log(array);
//output =>
["hello", "world"]
array = ["hello"]
array.push("world");
console.log(array);
//output =>
["hello", "world"]
array = ["hello"]
array.push("world");
//original array
String[] rgb = new String[] {"red", "green"};
//new array with one more length
String[] rgb2 = new String[rgb.length + 1];
//copy the old in the new array
System.arraycopy(rgb, 0, rgb2, 0, rgb.length);
//add element to new array
rgb2[rgb.length] = "blue";
//optional: set old array to new array
rgb = rgb2;
const new_array = old_array.concat([value1[, value2[, ...[, valueN]]]])
#include <vector>
#include <iostream>
int main() {
std::vector<int> v;
v.push_back(42);
std::cout << v.size() << "\n";
std::cout << v.back() << "\n";
}
Output:
1
42
const arr = ['First item', 'Second item', 'Third item'];
arr.push('Fourth item');
console.log(arr); // ['First item', 'Second item', 'Third item', 'Fourth item']