본문 바로가기

html | javascript

(28)
html javascript - array sort, reverse function init() { const arr0 = ['car','bus','aircraft','spacecraft','car1','motorcycle','car'] const arr1 = [ {name: 'car', type: 'land', cost: 100}, {name: 'bus', type: 'land', cost: 50}, {name: 'aircraft', type: 'sky', cost: 200}, {name: 'motorcycle', type: 'land', cost: 80}, {name: 'spacecraft', type: 'space', cost: 1000} ] const arr2 = [5,3,21,6,50,100,1,10,12,20,..
html javascript - array search (indexOf, find, includes) const arr0 = ['car','bus','aircraft','spacecraft','car','motorcycle','car']const index0 = arr0.indexOf('car')const index1 = arr0.lastIndexOf('car')console.log(index0) // 0console.log(index1) // 6const include0 = arr0.includes('bus')const include1 = arr0.includes('aircraft')const include2 = arr0.includes('warcraft')console.log(include0) // trueconsole.log(include1) // trueconsole.log(include2) //..
html javascript - array concat const arr0 = [1,2,3]const arr1 = [4,5,6]const arr2 = [7,8,9]const arr3 = arr0.concat(arr1, arr2)const arr4 = arr1.concat(arr2, arr0)const arr5 = arr0.concat(arr0, arr0)console.log(arr3) // [1,2,3,4,5,6,7,8,9]console.log(arr4) // [4,5,6,7,8,9,1,2,3]console.log(arr5) // [1,2,3,1,2,3,1,2,3]
html javascript - string replace const str0 = 'name: name-name-name, age: age-age-age'let str1 = str0.replace('name-name-name', 'Joker')str1 = str1.replace('age-age-age', '20')console.log(str1)// name: Joker, age: 20
html javascript - string split const str0 = '123456789'const str1 = '1,2,3,4,5,6,7,8,9'const str2 = '1/2/3/4/5/6/7/8/9'const split0 = str0.split('')const split1 = str1.split(',')const split2 = str2.split('/')console.log(split0)console.log(split1)console.log(split2)// ["1","2","3","4","5","6","7","8","9"]
html javascript - array join const arr = [1,2,3,4,5,6,7,8,9]const arrJoin0 = arr.join(',')const arrJoin1 = arr.join('/')let arrJoin2 = arr.join('won ') // 1won 2won 3won 4won 5won 6won 7won 8won 9arrJoin2 += 'won'const arrJoin3 = arr.join('')console.log(arrJoin0) // 1,2,3,4,5,6,7,8,9console.log(arrJoin1) // 1/2/3/4/5/6/7/8/9console.log(arrJoin2) // 1won 2won 3won 4won 5won 6won 7won 8won 9wonconsole.log(arrJoin3) // 123456789
html javascript - input txt file
html javascript - clear canvas let canvas = document.getElementById('id-canvas') let ctx = canvas.getContext('2d') function clear() { ctx.clearRect(0, 0, canvas.width, canvas.height) }