๋ฐ์ํ
๋ฐ์ดํฐ์ ์๊ฐ ๊ธธ์ด์ง๋ ๊ฒฝ์ฐ, find ๋ฅผ ํตํด์ ํน์ key ๊ฐ์์์ value ๋ฅผ ์ฐพ์๋ด์ผํ ๋๊ฐ ์กด์ฌํ๋ค.
๊ทธ๋, function ์ ์ฌ์ฉํ ๊ฒฝ์ฐ์ ํ์ดํ ํจ์๋ง ์ฌ์ฉํ ๊ฒฝ์ฐ๊ฐ ์๋ค.
์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ ๋ณด๋ฉด, ์ ํ์ดํ ํจ์๊ฐ ํธํ์ง ์ ๊ฒ์ด๋ค.
const settingState =
[
{
"engname": "template_name",
"korname": "ํฌํ๋ฆฟ ์ด๋ฆ",
"value": "ํ
์คํธ ํ
ํ๋ฆฟ 1"
},
{
"engname": "toffice_id",
"korname": "Toffice ์์ด๋",
"value": "22019"
},
{
"engname": "toffice_password",
"korname": "Toffice ๋น๋ฐ๋ฒํธ",
"value": "22019"
},
{
"engname": "esero_email",
"korname": "E-์ธ๋ก ๊ฒ์ ์์ด๋",
"value": "rps@gseps.comm"
},
{
"engname": "tax_code",
"korname": "์ธ๊ธ์ฝ๋",
"value": "์ ์/10%/์ผ๋ฐ"
},
{
"engname": "summary",
"korname": "์ ์",
"value": "ํ
์คํธ"
},
{
"engname": "comment",
"korname": "์๊ฒฌ",
"value": "1"
},
{
"engname": "ponum",
"korname": "PO๋ฒํธ",
"value": 1
},
{
"engname": "account_code",
"korname": "ํ์ ๊ณ์ ์ฝ๋",
"value": "1"
},
{
"engname": "sub_cost_center_code",
"korname": "ํ์ ์ฝ์คํธ ์ผํฐ ์ฝ๋",
"value": "1"
},
{
"engname": "sub_business_category",
"korname": "์ฌ์
์์ญ",
"value": "1"
},
{
"engname": "account_num",
"korname": "๊ณ์ข๋ฒํธ",
"value": "1"
},
{
"engname": "user_id",
"korname": "User ID",
"value": "22019"
}
];
// console.log(Object.keys(settingState));
// function getKeyByValue(obj, value) {
// return Object.keys(obj).find(key => obj[key] === value);
// }
// console.log(getKeyByValue(settingState, "esero_email"));
// console.log(Object.value(settingState))
// 1. ํ์ดํ ์ฌ์ฉํ์ง ์๊ณ ํจ์๋ฅผ ๋ง๋๋ ๊ฒฝ์ฐ
function isEmail(element) {
if(element.engname === "esero_email") {
return true;
}
}
const email = settingState.find(isEmail);
console.log(email);
console.log(email.value);
// 2. ํ์ดํ ํจ์๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ
const test = settingState.find(key => key.engname === "esero_email");
console.log(test);
console.log(test.value);
//ํ๋ฉด์ ๋ฐ๋ก ์ถ๋ ฅํ๋ ๊ฒฝ์ฐ (์์ ๋ฐฉ๋ฒ์ ์ํํ ๋๋ฒ๊น
์ ์ํด console๋ก ์ถ๋ ฅ)
// document.write(settingState.find(isEmail));
// document.getElementById('root').innerHTML = settingState.find(isEmail);
๋ฐ์ํ
'๐๏ธ์ํํธ์จ์ด > ๐JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[webpack-dev-server] ์ฝ๋ ๋ณ๊ฒฝ์ฌํญ ๋ฐ๋ก ๋ฐ์(js) (0) | 2023.01.11 |
---|---|
[Node.js] express ์ cors ์ฌ์ฉํด์ API ๋ง๋ค๊ธฐ (0) | 2022.12.19 |
[์๋ฐ์คํฌ๋ฆฝํธ] Math ํจ์ ์ด์ฉํ์ฌ ๋ก๋ ๋ฒํธ ์์ฑํ๊ธฐ (0) | 2022.11.08 |
[Vuetify] ๋๊ธฐ,๋น๋๊ธฐ, (0) | 2022.10.04 |
node ์ด์ฉํ json ์ฝ๋ฐฑ ํจ์ (0) | 2022.09.29 |