I use the following code to add space inside the inverted commas for some value ,there is nicer/elegant way to do it ?
text: x.fullPath + " " + x.name
I use the following code to add space inside the inverted commas for some value ,there is nicer/elegant way to do it ?
text: x.fullPath + " " + x.name
You can create a function which return the string joining the two values with the given number of space.
text: addSpace(x.fullPath, x.name, 5)
Will give you a new string joining these two values with 5 spaces.
You can use this function or
function addSpace(stringA, stringB, spaces){
return x.fullPath + Array(spaces).join(" ") + x.name;
}
A simple way would be to use this:
text: x.fullPath + Array(30+1).join(" ") + x.name
where 30
is the amount of spaces
This would be a function:
// text: addSpace(x.fullPath, x.name, 5)
function addSpace(stringA, stringB, spaceCount) {
var spaces = ""
for (var i = 0; i < spaceCount; ++i) {
spaces += " "
}
return stringA + spaces + stringB
}
// Demo
alert(addSpace("test1", "test2", 30))