javascript set value code example

Example 1: javascript set input field value

document.getElementById("myInputID").value = "My Value"; //set value on myInputID

Example 2: Javascript get text input value

var inputValue = document.getElementById("myTextInputID").value;

Example 3: set value using javascript

document.getElementById("myText").value = "your string";

Example 4: set in javascript

// set is used for storing unique values
const firstSet = new Set([1, 2, 3]);

firstSet.add('hi'); //adding value to set

firstSet.add(3); //this will not give any error and it will also not be added

firstSet.delete('hi');//removing value from set

console.log(firstSet.has('hi'));//checking 'hi' is in the set or not

// showing all values in the set
console.log(firstSet);
for (const entry of firstSet.values()) {
    console.log(entry);