سؤال

ما هي أسرع طريقة, لإضافة قيمة جديدة في بداية سلسلة?

هل كانت مفيدة؟

المحلول

giveacodicetagpre.

لن يعمل هذا لك؟

نصائح أخرى

يمكنك القيام بذلك بهذه الطريقة ..

giveacodicetagpre.

إخلاء المسئولية: http://xkcd.com/208/


انتظر، نسيت الهروب من المساحة. Whyeeee [Tapaptapap] Eeeeee.

منذ السؤال هو حول ما هو أسرع الطريقة ، اعتقدت أنني سأضيف بعض مقاييس الأداء.

ليرة تركية ؛ دكتور الفائز ، بهامش واسع ، هو + المشغل ، و من فضلك أبدا استخدام التعبير العادي

https://jsperf.com/prepend-text-to-string/1

enter image description here

ES6:

let after = 'something after';
let text = `before text ${after}`;

you could also do it this way

"".concat("x","y")

If you want to use the version of Javascript called ES 2015 (aka ES6) or later, you can use template strings introduced by ES 2015 and recommended by some guidelines (like Airbnb's style guide):

const after = "test";
const mystr = `This is: ${after}`;

Another option would be to use join

var mystr = "Matayoshi";
mystr = ["Mariano", mystr].join(' ');

You can use

var mystr = "Doe";
mystr = "John " + mystr;
console.log(mystr)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top