JavaScript中的來源RegExp屬性是RegExp物件的唯讀字串屬性。它包含RegExp模式的文字。此文字不包括正規表示式文字中使用的分隔斜杠,也不包括“g”、“i”和“m”屬性。範例您可以嘗試執行以下程式碼來了解如何在JavaScript中實作來源RegExp屬性-
JavaScriptRegExpsourcePrope</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 01:21 PM</span></div></div><hr /><div class="Articlelist_txts"><a href="https://m.php.cn/zh-tw/faq/599480.html" title="如何在 JavaScript 中將數字轉換為陣列?" class="Articlelist_txtsimg"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghw/default1.png"
data-src="https://img.php.cn/upload/article/000/465/014/169328671359874.jpg?x-oss-process=image/resize,m_fill,h_135,w_240" class="lazy"
alt="如何在 JavaScript 中將數字轉換為陣列?" /></a><div class="Articlelist_txts_info"><h3><a href="https://m.php.cn/zh-tw/faq/599480.html" title="如何在 JavaScript 中將數字轉換為陣列?" class="Articlelist_txts_title">如何在 JavaScript 中將數字轉換為陣列?</a></h3><p class="Articlelist_txts_p">在JavaScript中,有許多內建方法可以將數字轉換為陣列。最簡單的一種是split()方法。我們也可以使用map()、reduce()或form()方法來執行任務。本文討論了一些最受歡迎的將數字轉換為數組的方法,並提供了何時以及如何應用每種技術的範例。現在的問題是,為什麼需要將數字轉換為陣列?那麼原因可能是將電話號碼拆分為單獨的數字或將日期分解為其組成部分(解析日期),或者在對單獨的數字執行數學運算時它可能很有用。方法一:透過split()方法現在,我們來看看split()方法。它是一個有用的</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 01:25 PM</span></div></div><hr /><div class="Articlelist_txts"><a href="https://m.php.cn/zh-tw/faq/599560.html" title="在 JavaScript 中按屬性從物件陣列中提取唯一對象" class="Articlelist_txtsimg"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghw/default1.png"
data-src="https://img.php.cn/upload/article/000/000/164/169329439656956.jpg?x-oss-process=image/resize,m_fill,h_135,w_240" class="lazy"
alt="在 JavaScript 中按屬性從物件陣列中提取唯一對象" /></a><div class="Articlelist_txts_info"><h3><a href="https://m.php.cn/zh-tw/faq/599560.html" title="在 JavaScript 中按屬性從物件陣列中提取唯一對象" class="Articlelist_txts_title">在 JavaScript 中按屬性從物件陣列中提取唯一對象</a></h3><p class="Articlelist_txts_p">在本教程中,我們將學習按屬性從物件陣列中提取唯一物件。有時,我們需要根據特定屬性從物件陣列中過濾物件。例如,我們有一個id作為標識物件的鍵。因此,我們需要確保數組僅包含具有單一id的單一物件。如果兩個或多個物件包含相同的主鍵值,就會導致物件唯一標識的問題。在這裡,我們將學習根據特定屬性從陣列中過濾所有唯一物件的不同方法。使用地圖和for循環在JavaScript中,Map可以儲存唯一的鍵值對。此外,我們可以使用Map的鍵以O(1)的時間複雜度從Map中取得任何值。因此,我們將迭代物件數組並將鍵值</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 03:33 PM</span></div></div><hr /></div><div class="AI_ToolDetails_main4sR"><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/hotarticle2.png" alt="" /><h2>熱門文章</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600249.html" title="JavaScript:void 0報錯怎麼解決" class="phpgenera_Details_mainR4_bottom_title">JavaScript:void 0報錯怎麼解決</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>Byzbt</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600246.html" title="javascript void:0是什麼" class="phpgenera_Details_mainR4_bottom_title">javascript void:0是什麼</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>Byzbt</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600154.html" title="JavaScript 地理定位:建立位置感知應用程式" class="phpgenera_Details_mainR4_bottom_title">JavaScript 地理定位:建立位置感知應用程式</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>ByPHPz</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600125.html" title="如何在 JavaScript 中為 URL 新增參數?" class="phpgenera_Details_mainR4_bottom_title">如何在 JavaScript 中為 URL 新增參數?</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>ByWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/599925.html" title="JavaScript 程式求矩形的面積和周長" class="phpgenera_Details_mainR4_bottom_title">JavaScript 程式求矩形的面積和周長</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>By王林</span></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/article.html">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR3"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/hottools2.png" alt="" /><h2>熱工具</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/kits-ai" title="Kits AI" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/default1.png"
data-src="https://img.php.cn/upload/ai_manual/001/246/273/173417754263702.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Kits AI" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/kits-ai" title="Kits AI" class="phpmain_tab2_mids_title"><h3>Kits AI</h3></a><p>用人工智慧藝術家的聲音改變你的聲音。創建並訓練您自己的人工智慧語音模型。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/soundraw-ai-music-generator" title="SOUNDRAW - AI Music Generator" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/default1.png"
data-src="https://img.php.cn/upload/ai_manual/001/246/273/173417756684210.jpeg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="SOUNDRAW - AI Music Generator" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/soundraw-ai-music-generator" title="SOUNDRAW - AI Music Generator" class="phpmain_tab2_mids_title"><h3>SOUNDRAW - AI Music Generator</h3></a><p>使用 SOUNDRAW 的 AI 音樂產生器輕鬆為影片、電影等創作音樂。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/web-chatgptai" title="Web ChatGPT.ai" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/default1.png"
data-src="https://img.php.cn/upload/ai_manual/001/246/273/173399378227633.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Web ChatGPT.ai" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/web-chatgptai" title="Web ChatGPT.ai" class="phpmain_tab2_mids_title"><h3>Web ChatGPT.ai</h3></a><p>使用OpenAI聊天機器人免費的Chrome Extension,以進行有效的瀏覽。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/resume-yay" title="Resume Yay" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/default1.png"
data-src="https://img.php.cn/upload/ai_manual/001/246/273/174597651711009.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Resume Yay" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/resume-yay" title="Resume Yay" class="phpmain_tab2_mids_title"><h3>Resume Yay</h3></a><p>真正免費的AI簡歷構建器</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/bestcoloringpages" title="bestcoloringpages" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/default1.png"
data-src="https://img.php.cn/upload/ai_manual/001/246/273/174597649148886.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="bestcoloringpages" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/bestcoloringpages" title="bestcoloringpages" class="phpmain_tab2_mids_title"><h3>bestcoloringpages</h3></a><p>所有年齡和場合的免費可打印的AI著色頁。</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/ai">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
onerror="this.onerror=''; this.src='/static/imghwm/default1.png'"
src="/static/imghwm/hotarticle2.png" alt="" /><h2>熱門話題</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/winkawaksrom" title="winkawaksrom" class="phpgenera_Details_mainR4_bottom_title">winkawaksrom</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>208</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>3</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/jxbcxwtzmjj" title="解析包時出現問題怎麼解決" class="phpgenera_Details_mainR4_bottom_title">解析包時出現問題怎麼解決</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>1115</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/ynxfpcfa" title="有哪些防爬蟲的方法" class="phpgenera_Details_mainR4_bottom_title">有哪些防爬蟲的方法</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>262</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>8</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/javajyfynx" title="java就業方向有哪些" class="phpgenera_Details_mainR4_bottom_title">java就業方向有哪些</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>82</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/insertbefore" title="insertbefore和before的差別" class="phpgenera_Details_mainR4_bottom_title">insertbefore和before的差別</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>100</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/faq/zt">顯示更多</a></div></div></div></div></main><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>公益線上PHP培訓,幫助PHP學習者快速成長!</p></div><div class="footermid"><a href="https://m.php.cn/zh-tw/about/us.html">關於我們</a><a href="https://m.php.cn/zh-tw/about/disclaimer.html">免責聲明</a><a href="https://m.php.cn/zh-tw/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved
</p></div></div></footer><script>isLogin = "0";</script><!-- Matomo --><script> var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://tongji.php.cn/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '9']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script><!-- End Matomo Code --><script>
// 通用函数,用于显示或隐藏元素
function toggleElementsDisplay(className, show) {
const elements = document.getElementsByClassName(className);
for (let i = 0; i < elements.length; i++) {
elements[i].style.display = show ? "block" : "none";
}
}
// 绑定事件监听器
function bindEventListeners() {
const toggleDisplay = (className, show, eventId) => {
document.getElementById(eventId).addEventListener("click", (event) => {
event.preventDefault();
toggleElementsDisplay(className, show);
});
};
toggleDisplay("m_editormain12main", true, "fixed_tab_img");
toggleDisplay("m_editormain12main", false, "fixed_tab_topi");
toggleDisplay("m_editormain12main", false, "fixed_tab_close");
// 控制 m_menu 的显示和隐藏
toggleDisplay("m_menu", true, "lan1sp");
toggleDisplay("m_menu", false, "m_editormain12main_topi_sp");
// 控制 m_menu_lang 的显示和隐藏
toggleDisplay("m_menu_lang", true, "lan1");
toggleDisplay("m_menu_lang", false, "m_editormain12main_topi_lan");
}
// 在页面加载完成后绑定事件监听器
window.onload = bindEventListeners;
layui.use(function () {
var util = layui.util;
util.fixbar({
on: {
mouseenter: function (type) {
layer.tips(type, this, {
tips: 4,
fixed: true,
});
},
mouseleave: function (type) {
layer.closeAll("tips");
},
},
});
});
// 获取关闭按钮
const closeButton = document.querySelector(".phpgenera_Details_mainR1_close");
// 获取容器元素
const container = document.querySelector(".phpgenera_Details_mainR1");
// 添加点击事件监听器
closeButton.addEventListener("click", (event) => {
event.preventDefault(); // 阻止默认的<a>点击行为
container.style.display = "none"; // 隐藏容器
});
document.addEventListener("DOMContentLoaded", () => {
// 动态获取所有滚动链接及隐藏目标元素
const links = [{
linkId: "fixed_tab_a1",
targetId: "Topic_Details_mainL2_R_title1",
hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID
},
{
linkId: "fixed_tab_a2",
targetId: "Topic_Details_mainL2_R_title2",
hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID
},
{
linkId: "fixed_tab_a3",
targetId: "Topic_Details_mainL2_R_title3",
hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID
},
];
links.forEach(({
linkId,
targetId,
hideElementId
}) => {
const linkElement = document.getElementById(linkId);
const targetElement = document.getElementById(targetId);
const hideElement = document.getElementById(hideElementId);
if (linkElement && targetElement) {
linkElement.addEventListener("click", (e) => {
e.preventDefault(); // 阻止默认行为
// 隐藏指定元素
if (hideElement) {
hideElement.style.display = "none";
}
// 平滑滚动到目标元素
targetElement.scrollIntoView({
behavior: "smooth"
});
});
} else {
console.warn(
`Link, target, or hide element not found: ${linkId}, ${targetId}, ${hideElementId}`
);
}
});
});
</script></body></html>