한주간 사용한 함수

HeeChan·2020년 8월 2일
0

한주간

목록 보기
1/2

문자 , 배열

str.concat()

str.toUpperCase()

str.toLowerCase()

str.trim()

양 끝에서 공백을 제거한 새로운 문자열.
````js
	const str ='   hello   '
    console.log(str.trim());
    //"hellow"
````

str.indexOf(searchValue[,fromIndex])

	//이거에 활용도가 너무 어렵다.
	//배열의 값을 찾을 수 있으며 요소의 모든 항목도 찾을 수있고 업데이트 까지 할 수 있다.
	// 찾는 문자에 인덱스의 위치의 결과 값을 주며 없을시 -1 을 준다. 

str.lastindexOf()

문자열 뒤부터 찾는다. 

str.includes(searchStr)

문자열에 찾는 단어가 있는지를 판단하여 불린값을 준다.

str.split(지정문자)

지정 단어 간격으로 배열로 나눈다.
	const str = 'hi hello fuck !';
	
	const words = str.split(' ');

	console.log(words); //["hi", "hello", "fuck", "!"]
	console.log(words[2]);
	//"fuck"
	

arr.join()

배열의 모든 요소를 연결해 하나의 문자열로 만들어준다.

	const el = ['fuck' ,'you','man'];
	console.log(el.join());
	//fuck,you,man

str.substring(start index number,length num)

지정 인덱스 번호 의 문자만 출력

	const str = 'heechane';

	console.log(str.substring(1, 3));//"ee"

	console.log(str.substring(2));//"echane

str.slice(start,end)

어떤 배열의 시작 부터 끝 까지(끝 미포함) 에 대한 복사본을 새로운 배열 객체로 반환
원본 배열을 바뀌지 않습니다.

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]

Array.isArray(obj)

배열 인지 불린 형으로 판단

Array.isArray([1, 2, 3]);  // true
Array.isArray({foo: 123}); // false
Array.isArray('foobar');   // false
Array.isArray(undefined);  // false

Array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

배열의기존 요소를 삭제 또는 교체하거나 새 요소를 추가하여 배열의 내용을 변경

const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb'); // 시작 인덱스 , 시작인덱스로부터 몇 칸뒤 ,바꿀 문자열
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]

months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]

Math

Math.abs()

절대값

Math.pow()

제곱

Math.max() / min()

Math.floor()

반내림

Object

Object.keys(obj)

주어진 객체의 자체 열거 가능 속성 이름의 배열을 반환하며 , 일반 루프와 동한 순서로 반복

	const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]

Object.values(obj)

      const object1 = {
      a: 'somestring',
      b: 42,
      c: false
   		 };

  console.log(Object.values(object1));
  // expected output: Array ["somestring", 42, false]

for ...in / of 차이

for in (객체 순환)
for of (배열 순환)

in 은 객체 of 는 배열 그뿐이다.

profile
생각이란걸해

0개의 댓글