I am looking for a JavaScript push method to add value into array, in the style of:
title = document.getElementById('tit').value;
description = document.getElementById('desc').value;
if (localStorage.getItem('itemJson') == null) {
itemJsonArray = [];
itemJsonArray.push([title, description]);
localStorage.setItem('itemJson', JSON.stringify(itemJsonArray));
}
Just Use The Following Code To Add A Text To An Array Using Something Like This:
title = "First Element"
itemJsonArray = [];
itemJsonArray.push(title);
You can push multiple elements to the javascript array by using the below steps.
const arr = [];
arr.push('title', 'description');
console.log(arr); // 👉️ ['title', 'description']