// for me lol... pls don't delete!
// use splice to insert element
// arr.splice(index, numItemsToDelete, item);
var list = ["hello", "world"];
list.splice( 1, 0, "bye");
//result
["hello", "bye", "world"]
var list = ["foo", "bar"];
list.push("baz");
["foo", "bar", "baz"] // result
array.splice(index, 0, value);
void insert(int arr[], int N, int pos, int element)
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]
protected function build_sql_insert($table, $data) {
$key = array_keys($data);
$val = array_values($data);
$sql = "INSERT INTO $table (" . implode(', ', $key) . ") "
. "VALUES ('" . implode("', '", $val) . "')";
return($sql);
}
<!DOCTYPE html>
<html>
<body>
<p>In this code we will see how to push an element to array</p>
<button onclick="pushElementToArray()" id="btnClick">Click</button>
<p id="pId"></p>
<script>
var days = ["Sunday", "Monday", "Tuesday", "Wednsday"];
document.getElementById("pId").innerHTML = days;
function pushElementToArray() {
days.push("Saturday");
document.getElementById("pId").innerHTML = days;
}
</script>
</body>
</html>