{}
run-icon
main.js
// Online Javascript Editor for free // Write, Edit and Run your Javascript code using JS Online Compiler //logic // by two pointer approach const arr = [1,2,3,4]; let i = 0; let j = arr.length-1; while(i<j){ temp =arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } // for(x in arr){ // console.log(x); // it prints the keys(index) in the array not the values. // } // for(let x of arr){ // console.log(x); // it will print the values in the array. // } // for(let k = 0; k<arr.length;k++){ // it is also one method of printing the array. // console.log(arr[k]); // } // console.log(arr.join(" ")); //print the arr with sapces // if array need to print in the same line : // let result = ""; // for(let x of arr){ // result+=x+ " "; // } // console.log(arr.join(" ")); //another way to find the arr in same line console.log(...arr); //using spead operator
Output