Documentation can be found e.g. at MDN. Note that .split() is not a jQuery method, but a native string method.
If you use .split() on a string, then you get an array back with the substrings:
var str = 'something -- something_else';
var substr = str.split(' -- ');
// substr[0] contains "something"
// substr[1] contains "something_else"
If this value is in some field you could also do:
tRow.append($('<td>').text(
=txtEntry2]').val().split(' -- ')[0])));
Answer from Felix Kling on Stack Overflow
Videos
Documentation can be found e.g. at MDN. Note that .split() is not a jQuery method, but a native string method.
If you use .split() on a string, then you get an array back with the substrings:
var str = 'something -- something_else';
var substr = str.split(' -- ');
// substr[0] contains "something"
// substr[1] contains "something_else"
If this value is in some field you could also do:
tRow.append($('<td>').text(
=txtEntry2]').val().split(' -- ')[0])));
If it is the basic JavaScript split function, look at documentation, JavaScript split() Method.
Basically, you just do this:
var array = myString.split(' -- ')
Then your two values are stored in the array - you can get the values like this:
var firstValue = array[0];
var secondValue = array[1];
There are several functions in JavaScript which can be used to split a string.
1. Split - (Split a string into an array of substrings)
var str = "This is a string";
var str = "This is a string";
var res = str.split(" ");
console.log(res);
It is important that split gives back an array with the string chunks.
2. Substr - (Extract parts of a string)
var str = "This is a string";
var res = str.substr(1, 4);
console.log(res);
3. Substring - (Extract characters from a string)
var str = "This is a string";
var res = str.substring(1, 4);
console.log(res);
Reference
W3Schools Split
W3Schools Substr
W3Schools Substring
I think you want to use substring() (read more here: https://www.w3schools.com/jsref/jsref_substring.asp)
For example,
var str = "Hello world!";
var res = str.substring(1, 4);
would be equivalent to this Python code:
str = "Hello world!"
res = str[1:4]
res would be 'ell'. The start and end indices work the same as in Python (includes the start index, goes through but not including the end index.
Use the .split() method. When specifying an empty string as the separator, the split() method will return an array with one element per character.
entry = prompt("Enter your name")
entryArray = entry.split("");
ES6 :
const array = [...entry]; // entry="i am" => array=["i"," ","a","m"]