Array sample

 <!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="item">
    <button onclick="Add();">Add</button>
    <ol id="list">
       
    </ol>
</body>
<script>

let a=[];
function Add(){
    let item=document.getElementById("item").value;
    a.push(item);
    Display();
}

function Display(){
    let list=document.getElementById("list");
    list.innerHTML="";
    a.map((item,index)=>{
        list.innerHTML=  list.innerHTML+` <li>${item}</li>`;
    });
}

    // let a=[1,2,3];
    // console.log(a);
    // a.push(5,1,3,4);
    // console.log(a);
    // a.pop();
    // console.log(a);

    // let a=[];
    // for(let i=1;i<=50;i++){
    //     a.push(i);//Math.random(100)
    // }
    // let b=[];
    // for(let i=0;i<=10;i++){
    //     b.push(i);
    // }


    // b.shift()//remove element from start position
    // b.unshift()//add one or more element from start position

    // b.slice()// Clone selected element (PositionIndex,<EndPositionIndex);
    // b.splice()//delete selected element (PositionIndex,NumberOfItem);

    // b.includes(90);//finde item if available then return true other wise return false




</script>
</html>

Comments

Popular posts from this blog

App 1st User Define Component

Example 1

Rabiit