250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- concept
- useState
- CSS
- blockchain
- typeScript
- error
- evm
- Interface
- hardhat
- Props
- Ethereum
- middleware
- graphQL
- HTML
- JavaScript
- SSR
- web
- API
- solidity
- built in object
- REACT
- bitcoin
- CLASS
- 기준
- Redux
- express.js
- 삶
- nextJS
- node.js
- tailwindcss
Archives
- Today
- Total
ReasonJun
javascript : built-in object (object, string) 본문
728x90
object
//? Object.assign()
// Copies properties from one or more objects to a target object and returns the target object.
const target = { a: 1, b: 2 };
const source1 = { b: 3, c: 4 };
const source2 = { c: 5, d: 6 };
const result = Object.assign(target, source1, source2);
const result1 = {
...target,
...source1,
...source2,
};
console.log(target); // { a: 1, b: 3, c: 5, d: 6 }
console.log(result); // { a: 1, b: 3, c: 5, d: 6 }
console.log(result1); // { a: 1, b: 3, c: 5, d: 6 }
//? Object.entries()
// Creates an array with each property and value of the given object and returns a two-dimensional array with elements added.
const user = {
name: 'youjun',
age: 85,
isValid: true,
email: 'wefwe@gmail.com',
};
console.log(Object.entries(user));
// [
// [ 'name', 'youjun' ],
// [ 'age', 85 ],
// [ 'isValid', true ],
// [ 'email', 'wefwe@gmail.com' ]
// ]
for (const [key, value] of Object.entries(user)) {
console.log(key, value);
}
// name youjun
// age 85
// isValid true
// email wefwe@gmail.com
//? Object.keys()
// Returns an array listing the property names of the given object.
console.log(Object.keys(user)); //[ 'name', 'age', 'isValid', 'email' ]
//? Object.values()
// Returns an array listing the property values of the given object.
console.log(Object.values(user)); // [ 'youjun', 85, true, 'wefwe@gmail.com' ]
string
const textObj = new String('Hello World!');
const text = 'Hello World!';
console.log(textObj); // [String: 'Hello World!']
console.log(text); // Hello World!
console.log(text.charAt(0)); // H
console.log(text.charAt(1)); // e
console.log(text.charAt(2)); // l
console.log(text.startsWith('He')); // ture
console.log(text.endsWith('!')); // ture
console.log(text.substring(0, 2)); // He
//? .length
// Returns the length (number) of characters.
const str = 'hello world';
console.log(str.length); // 1
//? .includes()
// Checks if the character contains the given character (boolean).
console.log(str.includes('hello', 0)); // true
console.log(str.includes('hello', 1)); // false
//? .indexOf()
// Returns the first index (number) in the target character that matches the given character.
// Returns -1 if no character is matched
console.log(str.indexOf('world')); // 6
console.log(str.indexOf('you')); // -1
//? .padEnd()
// If the length of the target character is less than the specified length,
// Returns a new character appended to the end of the given character up to the specified length.
const str1 = '1234567';
console.log(str1.padEnd(10, '0')); // 1234567000
console.log(str1); // 1234567
//? .padStart()
// If the length of the target character is less than the specified length,
// Returns a new character prefixed with the given character up to the specified length.
console.log(str1.padStart(10, '0')); // 0001234567
//? .replace()
//Returns a new character replacing the portion of the target character that matches the pattern.
const str = 'Hello, Hello?!';
console.log(str.replace('Hello', 'Hi')); // Hi, Hello?!
console.log(str.replace(/Hello/g, 'Hi')); // Hi, Hi?!
console.log(str); // Hello, Hello?!
//? .split()
// Divides the target characters by the given delimiter and returns them as an array.
const str2 = 'apple, banana, cherry';
console.log(str2.split(', ')); // [ 'apple', 'banana', 'cherry' ]
console.log(str2.split(''));
// [
// 'a', 'p', 'p', 'l', 'e',
// ',', ' ', 'b', 'a', 'n',
// 'a', 'n', 'a', ',', ' ',
// 'c', 'h', 'e', 'r', 'r',
// 'y'
// ]
const longText = 'Get to the, point';
console.log(longText.split(' ')); // [ 'Get', 'to', 'the,', 'point' ]
console.log(longText.split(' ', 2)); // [ 'Get', 'to' ]
console.log(longText.split(', ', 2)); // [ 'Get to the', 'point' ]
return new string
//? .slice()
// Extracts part of the target character and returns a new character.
// Extracts up to just before the second argument, or until the end of the target character if the second argument is omitted.
const str1 = 'Hello world!';
console.log(str1.slice(0, 5)); // Hello
console.log(str1.slice(6, -1)); // world
console.log(str1.slice(6)); // world!
console.log(str1); // Hello world!
//? .toLowerCase()
// Converts the target character to English lowercase and returns it as a new character.
const str3 = 'Apple, Banana, Cherry';
console.log(str3.toLowerCase()); // apple, banana, cherry
console.log(str3); // Apple, Banana, Cherry
//? .toUpperCase()
console.log(str3.toUpperCase()); // APPLE, BANANA, CHERRY
//? .trim()
// Returns a new character with leading and trailing whitespace characters removed from the target character.
const str4 = ' youjun ';
console.log(str4.trim()); //youjun
console.log(str4); // youjun
javascript : built-in object (object, string)
728x90
'Frontend > Javasciprt' 카테고리의 다른 글
Javascript : class (0) | 2023.06.07 |
---|---|
javascript : built-in object (time, json) (0) | 2023.06.07 |
javascript : built-in object (number, math, url) (0) | 2023.06.07 |
javascript : variable (4) (array, shallow copy) (4) | 2023.06.07 |
Javascript : Variable (3) (truthy, falsy, object) (0) | 2023.06.07 |
Comments