我低于陣列。
Array [
"??? 2017",
"???? 2017",
"????? 2018",
"?????? 2018",
"??? 2018",
"??? 2018",
"???? 2018",
"?????? 2019",
"?????? 2020",
"?????? 2020",
"????? 2020",
"????? 2021",
]
我有一個英文月份陣列。
const englishMonthArray = [
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
]
我如何才能將上述陣列的月份與英文月份相匹配?謝謝
uj5u.com熱心網友回復:
創建一個字典物件,將希伯來月份(鍵)映射到對應的英文月份(值)。
map在陣列上。split空格上的字串,從字典中獲取英文月份,然后回傳一個新的字串。
const arr=["??? 2017","???? 2017","????? 2018","?????? 2018","??? 2018","??? 2018","???? 2018","?????? 2019","?????? 2020","?????? 2020","????? 2020","????? 2021"];
const dict = {
?????: 'January',
??????: 'February',
???: 'March',
????????: 'April',
???: 'May',
????: 'June',
????: 'July',
??????: 'August',
????: 'September',
????: 'October',
??????: 'November',
?????: 'December'
};
const out = arr.map(el => {
// This was interesting. For an English string
// this would be destructured like [year, month].
// I'm assuming that because there's Hebrew in the string
// JS/the browser reads it differently (right to left).
const [ month, year ] = el.split(' ');
const enMonth = dict[month];
return `${year} ${enMonth}`;
});
console.log(out);
附加檔案
模板/字串文字
解構賦值
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/363671.html
標籤:javascript 数组 反应 反应原生
下一篇:使用月對兩個物件陣列進行聚類
