JavaScript Array Methods Part – 2

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

Program 1

// Array  methods in Java Script
"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})
// let city=["indore","agra","bhopal","delhi","mumbai","Ujjain","Raipur"]

let myar=[12,4,7,8,244,88,34,22,98,12]

let max=myar[0]
let p=0
for(let i=1;i<myar.length;i++)
{
    if(myar.at(i)>max)
    {
        max=myar.at(i)
        p=i
    }    
}
console.log("Maximum element is "+max)
console.log("Poisition of element is "+p)


// myar.forEach(element => 
//     {
//              if(element>max)
//                 max=element
//   });






















// for(let i=0;i<city.length;i++)
//     console.log(city.at(i))

// city.reverse()

// console.log("--------------------------------------")
// for(let i=0;i<city.length;i++)
//     console.log(city.at(i))











// const firstarr = [10, 20, 30, 40, 50, 60];
// const newarr = firstarr.flatMap(x => [x, x * 10]);
// console.log(newarr)



// let city=["indore","agra","bhopal","delhi","mumbai","Ujjain","Raipur"]
// let city1=[]
// for(let i=0;i<city.length;i++)
//     console.log(city.at(i))

// for(let i=0;i<city.length;i++)
// {
//    city1.push(city.at(i).toUpperCase())
// }
// console.log("--------------------------------------")
// for(let i=0;i<city.length;i++)
//     console.log(city1.at(i))














// Program for searching
// let myar=new Array()
// let choice,x
// while(true)
// {
//       x=parseInt(prompt("Enter a number"))
//       myar.push(x)
//       choice=prompt("Want to continue(y/n): ")
//       choice=choice.toLowerCase()
//       if(choice=="n")
//         break
// }
// myar.forEach(element => 
//     {
//           console.log(element)  
//    });
// let s=parseInt(prompt("Enter a number for search: "))
// //if(myar.includes(s))
// if(myar.indexOf(s)!=-1)
//     console.log("Searching success")
// else
//   console.log("Searching not success")

 

Your opinion matters
Please write your valuable feedback about DataFlair 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 *