//Confirms { const arr = [confirm('Ты мужчина?'),confirm('Ты женщина?'),confirm('Тебе больше 18-ти лет?')] console.log(arr)//[true, false, true] } //Prompts { const arr = [] arr[0]=prompt('Ты мужчина?') arr[1]=prompt('Ты женщина?') arr[2]=prompt('Тебе больше 18-ти лет?') console.log(arr)// ['да', 'нет', 'да'] } //Item access { const arr = ['нулевой','первый','второй'] indexArr = prompt('Введите индекс массива') console.log(arr[indexArr]) } //Item change { const arr = ['нулевой','первый','второй'] indexArr = prompt('Введите индекс массива')//если тут будет '2' meaningArr = prompt('Введите значение для выбраного индекса')// а тут слово 'четвертый' arr[indexArr]= meaningArr console.log(arr)// то здесь будет такой массив ['нулевой', 'первый', 'четвертый'] } //Multiply table { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] console.log(arr[3][4])// ответ 12 } //Multiply table slice { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] let arr2 = [arr[1].slice(1),arr[2].slice(1),arr[3].slice(1),arr[4].slice(1)] } //IndexOf Word { let str = prompt('Введите строку из несколький слов').split(' '); let strIndex = prompt('Введите искомое слово'); let arr = str.indexOf(strIndex); if (arr === -1){ alert('Слово не найдено'); } else{alert('Ваше слово '+(arr+1)+'-е по счету');} } //Reverse { let arr = [] arr.push(prompt('Введите первый элемент')) arr.push(prompt('Введите второй элемент')) arr.push(prompt('Введите третий элемент')) arr.push(prompt('Введите четвертый элемент')) arr.push(prompt('Введите пятый элемент')) let arr2 = [] arr2.push(arr.pop()) arr2.push(arr.pop()) arr2.push(arr.pop()) arr2.push(arr.pop()) arr2.push(arr.pop()) console.log(arr2) //Reverse 2 let arr3 = [] arr3.unshift(arr2.shift()) arr3.unshift(arr2.shift()) arr3.unshift(arr2.shift()) arr3.unshift(arr2.shift()) arr3.unshift(arr2.shift()) } //Copy { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] const arr2 = arr } //Deep Copy { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] const arr2 = arr.slice() } //Array Equals { const arr = [1,2,3] const arr2 = arr arr === arr2//true } //Flat { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] const arr2 = [...arr[0],...arr[1],...arr[2],...arr[3],...arr[4]] console.log(arr2.length)//25 } //Destruct { let str = prompt('Введите текст') const [a,,,,b,,,,c] = str alert(a+b+c) } //Destruct default { let str = prompt('Введите текст') const [a='!',,,,b='!',,,,c='!'] = str alert(a+b+c) } //Multiply table rest { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] const [,[,...a],[,...b],[,...c],[,...d]] = arr const arr2 = [a,b,c,d] const arr3 = [...arr2[0],...arr2[1],...arr2[2],...arr2[3]] console.log(arr3) // [1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16] } //For Alert { const names = ["John", "Paul", "George", "Ringo"] for (let name of names) { alert(`Hello, ${name}`) } } //For Select Option { const currencies = ["USD", "EUR", "GBP", "UAH"] let str = "" document.write(str) } //For Table Horizontal { const names = ["John", "Paul", "George", "Ringo"] let str = "" for (let namesTable of names){ str += '' } str+= "
'+namesTable+'
" document.write(str) } //For Table Vertical { const names = ["John", "Paul", "George", "Ringo"] let str = "" for (let namesTable of names){ str += '' } str+= "
'+namesTable+'
" document.write(str) } //For Table Letters { const currencies = ["USD", "EUR", "GBP", "UAH"] let str = "" for (let currency of currencies){ str += '' console.log(currency) for (let letter of currency){ str += '' console.log(letter) } str += '' } str+= "
'+letter+'
" document.write(str) } //For Multiply Table { const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]] let str = "" for (let currency of arr){ str += '' for (let letter of currency){ str += '' } str+= '' } str+= "
'+letter+'
" document.write(str) } //Function Capitalize { const capitalize = str => { let result result=str[0].toUpperCase()+str.toLowerCase().slice(1) return result } console.log(capitalize("cANBerRa")) //Canberra } //Map Capitalize { let str = prompt('Введите строку').split(' ') const capitalize = str => { let result = str[0].toUpperCase()+str.toLowerCase().slice(1) return result } let arr = str.map(capitalize).join(' ') alert(arr) } //Filter Lexics const arr = ['бляха', 'муха', "пляха", "шабля"] let motherWord = prompt('Введите строку').split(' ') let result = motherWord.filter(element => arr.indexOf(element)=== -1) alert(result.join(' ')) //Beep Lexics { const arr = ['бляха', 'муха', "пляха", "шабля"] let motherWord = prompt('Введите строку').split(' ') let arr2 = [] for (let el of arr){ motherWord = motherWord.map(x => x===el ?x='BEEP':x) } alert(motherWord.join(' ')) } //Reduce HTML { const currencies = ["","USD", "EUR", "GBP", "UAH"] let str = "" document.write(str) }