This Gist was automatically created by Carbide, a free online programming environment.
-
-
Save z81/d783798cedc6f0689b4d4c1b7f6bcf82 to your computer and use it in GitHub Desktop.
Smiley Face
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2].map(v => v + ' я строка'); ///трансформирует элменты массива | |
['saha', 'masha', 'gleb'].filter(v => v.includes('a')); | |
///филтьтрует массив оставляя элементы для которых калбэк вернул тру | |
['saha', 'masha', 'gleb'].reduce((prev, cur) => prev + '_' + cur, ''); | |
///трансформирует массив в какое то значение | |
['a', 'b', 'ccc'].join('+++'); ///соединяет массив через подстроку | |
'aaa/bbb/ccc'.split('/'); ///разибвает через опредленую подстроку | |
[1, 2, 3].every(a => a > 2); ///для кадого калбек должен вернуть тру | |
[1, 2, 3].some(a => a > 2); ///хотя бы для одного колбек вернет тру | |
[1, 2, 3].indexOf(2); ///Возвращает индекс элемента в массиве | |
[1].concat([3, 4]).concat(5); ///Объединяет двма массива | |
[1, 2, 3, 4].fill('+'); ///Заполняет массив значением | |
[1, 2, 3, 4].reverse(); ///переворачивает массив | |
[1, 2, 3, 4].find(v => v > 1 && v < 4); ///вернет первый элемент для кторого в колбэке вернет тру | |
[1, 2, 3, 4].findIndex(v => v > 1 && v < 4); | |
[1, [2, 3], [4, 5]].flat(); | |
[1, 2, 3].includes(4); | |
[1, 2, 3, 4].slice(1, 2); ///возвращает массив с элементами от 1 до 2 | |
[1, 2, 3, 4].splice(1, 2); ///два элемента после первого | |
// Объекты | |
Object.assign({ | |
a: 1 | |
}, {b: 2}); | |
Object.keys({a: 1, b: 2, c: 3}); | |
Object.values({a: 1, b: 2, c: 3}); | |
Object.entries({a: 1, b: 2, c: 3}); | |
Object.fromEntries([ | |
['a', 1], | |
['b', 2], | |
['c', 3] | |
]); | |
// Строки | |
'abcdef'.concat('def'); | |
'123' + '456'; | |
`123${45}6`; | |
'1234'.endsWith(4); | |
'1234'.startsWith(1); | |
'Ha'.repeat(5); | |
'1234'.includes(3); | |
'1234'.indexOf('2'); | |
'*'.padStart(5, '+'); | |
'*'.padEnd(5, '+'); | |
'123454321'.replace(4, 'A'); | |
'123454321'.replaceAll(4, 'A'); | |
'123454321'.slice(2, 5); | |
'123454321'.slice(-4); | |
' 123454321 '.trim(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment