Array in JavaScript

Full Stack Web Development Courses with Real-time projects Start Now!!

Program 1

// Array in Java Script
"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})

// const stname=["sonu","monu","montu","rajesh","Vivek","Nilesh"] // subscript
//             //            0         1          2            3          4         5
// console.log(stname.length)
// for(i=0;i<stname.length;i++)
// {
//     console.log(stname[i])
// }

// const stname=new Array(5)
// console.log("Enter element in array")
// let sname,i
// for(i=0;i<10;i++)
// {
//     sname=prompt("Enter Name: ")
//     stname.push(sname)
// }
// console.log(stname)

// let city=[]
// let ctname
// let i
// for(i=0;i<5;i++)
// {
//     ctname=prompt("Enter Name: ")
//     city.push(ctname)
// }
//   console.log(city)

let city=new Array()
let i,ctname,choice
while(true)
{
    ctname=prompt("Enter City name: ")
    city.push(ctname)
    choice=prompt( "Want to continue(Y/N): ")
    choice=choice.toUpperCase()
    if(choice=='N')
           break
}
for(i=0;i<city.length;i++)
{
    console.log(city[i])
}
console.log("-------------------------------")

 city.sort()
 
// city.forEach(element => 
//     {
//          console.log(element) 
//    });
city
console.log(city) 
// for(i=0;i<city.length;i++)
//     {
//         console.log(city.at(i))
//     }




// let abc=[101,"Vivek",78.88,true]

// console.log(abc)

 

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *