I'm newbie in javascript. I was searching in google and in stackoverflow and I can't find explains. I have an input which must save in json and I wan't to show it in console. I have added elements from inputs to array, but it was still adding in one array. I want have something like this:
[
{"id":"1","name":"Anna"},
{"id":"2","name":"Mark"}
]
And I want to delete one object from the array when I check it on site and click "Delete" button.
var arr = [];
function addTo() {
arr.push(document.getElementById("index").value);
arr.push(document.getElementById("name").value);
arr.push(document.getElementById("surname").value);
console.log(arr);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<select id="index" name="index">
<option hidden="" >Index</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input placeholder="Name" type="text" id="name"/>
<input placeholder="Surname" type="text" id="surname"/>
<input type="button" onclick="remove()" value="Delete"/>
<input type="button" onclick="addTo()" value="Add"/>
</body>
</html>