簡體   English   中英

如何使用JavaScript將單詞包裝在單個冒號和逗號分隔的單詞中

[英]How to wrap word in single colon and separate words with comma using javascript

我有以下格式的abc約100個字
高清

FGG
ASD
依此類推...直到n個數字

我希望它像'abc','def','eft'等...

基本上我想在數據庫中插入一行。

我真的很困惑。 你們能用邏輯幫助我嗎? 我有大量清單無法手動執行。

這是多種方法之一

var source = document.querySelector("pre").textContent;

var items = source.split("\n"); //Split items by new line
items = items.map(function(item) { //Trim whitespace off of each item
    return item.trim(); 
}).filter(function(item) { //Filter out empty items
    return item;
});

var list = "'" + items.join("','") + "'"; //Join items together by single quotes and comas, and add single quotes at the beggining and the end
alert(list);

http://jsfiddle.net/m1n7xc6r/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM