I've been trying to experiment in a way in which i can store values entered from a textbox into an array.(using JavaScript or JQuery)
I understand I can do it this way:
var array = []; var input = document.getElementById('input_id').value; array.push(input);
But the functionality that I want to achieve is to be able to give the user an option to choose which array they want to save their input to.
Summary:
Try to use an object with keys as the options you want to give to the user and its value as array.
{'opt1':[],'opt2':[],...}
When the user selects his option get that array and obj['opt'].push(inputValue)
. If the option does not exist then initialize a new array obj['someKey'] = []
and start pushing into it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.