Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

push input value to array javascript

var names = ['Riley', 'Takit', 'Maria', 'Oprah']
var input = document.querySelector('input');
var button = document.querySelector('button');

// Let's say the user types in a name like 'Emeka' in the input section

button.onclick = () => {
  var newName = input.value; // Captures the value of the input when the button is clicked
  names.push(newName);		 // This updates the existing names array adding the newName to the end of the array
  console.log(names);        // Result: ['Riley', 'Takit', 'Maria', 'Oprah', 'Emeka']
}

// Pen here 'https://codepen.io/emekaorji/pen/yLvNWaP'
// A better pen here 'https://codepen.io/emekaorji/pen/YzeXjvr'
Comment

PREVIOUS NEXT
Code Example
Javascript :: async queue.push 
Javascript :: why do you have to set key prop in react 
Javascript :: js maximum number value 
Javascript :: react firebase hooks 
Javascript :: flutter http request 
Javascript :: js filter array of objects by value 
Javascript :: chartjs disable animation 
Javascript :: mongodb import from json 
Javascript :: react native android safeareaview 
Javascript :: how to modify external json file javascript 
Javascript :: how to update kali linux on virtualbox 
Javascript :: mongoose limit 
Javascript :: if input value is null do something 
Javascript :: JAVASCRIPT KEYDOWN AROW 
Javascript :: javascript console log execution time 
Javascript :: next js absolute path 
Javascript :: require is not defined on html script with electron 
Javascript :: vue watch props 
Javascript :: commonjs vs es6 
Javascript :: localstorage 
Javascript :: add char in specific index stirng javascript 
Javascript :: hello word in js 
Javascript ::  
Javascript :: eslintrc ignore rule 
Javascript :: react disable eslint errors 
Javascript :: all ajaxcomplete event 
Javascript :: random item from array javascript 
Javascript :: out of memory gc overhead limit exceeded. react native 
Javascript :: javascript autoscroll 
Javascript :: reload page with parameters javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =