How to use String.raw on array variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a problem in my code, i have defined arrays but it contain special characters like /, {}, (), ,
etc... (because of plainsource MathJax)
The array returns the string without those mentioned special characters
PS: I've read about String.raw
but i have no idea how to use it in this kind of array. Help me please :(
var Array_QA = {
"Large {lim_{x to 2}} (5^x + 2^x + 4)" : "33",
"Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
javascript jquery mathjax
add a comment |
I have a problem in my code, i have defined arrays but it contain special characters like /, {}, (), ,
etc... (because of plainsource MathJax)
The array returns the string without those mentioned special characters
PS: I've read about String.raw
but i have no idea how to use it in this kind of array. Help me please :(
var Array_QA = {
"Large {lim_{x to 2}} (5^x + 2^x + 4)" : "33",
"Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
javascript jquery mathjax
add a comment |
I have a problem in my code, i have defined arrays but it contain special characters like /, {}, (), ,
etc... (because of plainsource MathJax)
The array returns the string without those mentioned special characters
PS: I've read about String.raw
but i have no idea how to use it in this kind of array. Help me please :(
var Array_QA = {
"Large {lim_{x to 2}} (5^x + 2^x + 4)" : "33",
"Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
javascript jquery mathjax
I have a problem in my code, i have defined arrays but it contain special characters like /, {}, (), ,
etc... (because of plainsource MathJax)
The array returns the string without those mentioned special characters
PS: I've read about String.raw
but i have no idea how to use it in this kind of array. Help me please :(
var Array_QA = {
"Large {lim_{x to 2}} (5^x + 2^x + 4)" : "33",
"Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
javascript jquery mathjax
javascript jquery mathjax
edited Jan 4 at 12:09
Jai
64.5k105782
64.5k105782
asked Jan 4 at 12:06
Acz FlorencioAcz Florencio
161
161
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Because the backslash is an escape character in javascript strings, you need to double it if you want it to appear in a string literal. Try
var Array_QA = {
"\Large {\lim_{x \to 2}} (5^x + 2^x + 4)" : "33",
"\Large {\lim_{x \to 2}} \frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
add a comment |
String.raw
is used with template literals, the new(ish) ES6 syntax for strings with interpolated variables, embedded quotes and newlines, and the optional application of "tags" (which are just function callbacks that receive the pieces of the template split up by each interpolated variable to return the final combined string however you like).
So if I have a function that processes a template literal, and it's called processLiteral
, then I could do something like this to apply it to a literal:
processLiteral`This is a string with interpolated variables like ${someVar} and also ${otherVar}.`
Specifically, String.raw
is meant to be used as the tag of a template literal, and it will return the raw string without processing any escaped characters. Meaning n
will remain as n
and not become a newline, t
will remain as t
and not become a tab, etc. It does this by automatically adding slashes before any escaping slashes, thereby escaping them, so it's equivalent to using \n
, \t
, etc.
So in your case, if you want to use that method, since you can't put template literals directly in an object key declaration (it doesn't parse correctly), you'd do something like this:
var Array_QA = {};
Array_QA[String.raw`Large {lim_{x to 2}} (5^x + 2^x + 4)`] = "33";
Array_QA[String.raw`Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}`] = "0";
That said, having complex strings like that as object keys is probably not a good idea from the start... but it should work. I'd suggest refactoring your code to do that differently, if you can.
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038669%2fhow-to-use-string-raw-on-array-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because the backslash is an escape character in javascript strings, you need to double it if you want it to appear in a string literal. Try
var Array_QA = {
"\Large {\lim_{x \to 2}} (5^x + 2^x + 4)" : "33",
"\Large {\lim_{x \to 2}} \frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
add a comment |
Because the backslash is an escape character in javascript strings, you need to double it if you want it to appear in a string literal. Try
var Array_QA = {
"\Large {\lim_{x \to 2}} (5^x + 2^x + 4)" : "33",
"\Large {\lim_{x \to 2}} \frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
add a comment |
Because the backslash is an escape character in javascript strings, you need to double it if you want it to appear in a string literal. Try
var Array_QA = {
"\Large {\lim_{x \to 2}} (5^x + 2^x + 4)" : "33",
"\Large {\lim_{x \to 2}} \frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
Because the backslash is an escape character in javascript strings, you need to double it if you want it to appear in a string literal. Try
var Array_QA = {
"\Large {\lim_{x \to 2}} (5^x + 2^x + 4)" : "33",
"\Large {\lim_{x \to 2}} \frac {x^2 - 6x + 8}{x^3 - 4}" : "0"
};
answered Jan 5 at 18:14
Davide CervoneDavide Cervone
7,3531936
7,3531936
add a comment |
add a comment |
String.raw
is used with template literals, the new(ish) ES6 syntax for strings with interpolated variables, embedded quotes and newlines, and the optional application of "tags" (which are just function callbacks that receive the pieces of the template split up by each interpolated variable to return the final combined string however you like).
So if I have a function that processes a template literal, and it's called processLiteral
, then I could do something like this to apply it to a literal:
processLiteral`This is a string with interpolated variables like ${someVar} and also ${otherVar}.`
Specifically, String.raw
is meant to be used as the tag of a template literal, and it will return the raw string without processing any escaped characters. Meaning n
will remain as n
and not become a newline, t
will remain as t
and not become a tab, etc. It does this by automatically adding slashes before any escaping slashes, thereby escaping them, so it's equivalent to using \n
, \t
, etc.
So in your case, if you want to use that method, since you can't put template literals directly in an object key declaration (it doesn't parse correctly), you'd do something like this:
var Array_QA = {};
Array_QA[String.raw`Large {lim_{x to 2}} (5^x + 2^x + 4)`] = "33";
Array_QA[String.raw`Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}`] = "0";
That said, having complex strings like that as object keys is probably not a good idea from the start... but it should work. I'd suggest refactoring your code to do that differently, if you can.
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
add a comment |
String.raw
is used with template literals, the new(ish) ES6 syntax for strings with interpolated variables, embedded quotes and newlines, and the optional application of "tags" (which are just function callbacks that receive the pieces of the template split up by each interpolated variable to return the final combined string however you like).
So if I have a function that processes a template literal, and it's called processLiteral
, then I could do something like this to apply it to a literal:
processLiteral`This is a string with interpolated variables like ${someVar} and also ${otherVar}.`
Specifically, String.raw
is meant to be used as the tag of a template literal, and it will return the raw string without processing any escaped characters. Meaning n
will remain as n
and not become a newline, t
will remain as t
and not become a tab, etc. It does this by automatically adding slashes before any escaping slashes, thereby escaping them, so it's equivalent to using \n
, \t
, etc.
So in your case, if you want to use that method, since you can't put template literals directly in an object key declaration (it doesn't parse correctly), you'd do something like this:
var Array_QA = {};
Array_QA[String.raw`Large {lim_{x to 2}} (5^x + 2^x + 4)`] = "33";
Array_QA[String.raw`Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}`] = "0";
That said, having complex strings like that as object keys is probably not a good idea from the start... but it should work. I'd suggest refactoring your code to do that differently, if you can.
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
add a comment |
String.raw
is used with template literals, the new(ish) ES6 syntax for strings with interpolated variables, embedded quotes and newlines, and the optional application of "tags" (which are just function callbacks that receive the pieces of the template split up by each interpolated variable to return the final combined string however you like).
So if I have a function that processes a template literal, and it's called processLiteral
, then I could do something like this to apply it to a literal:
processLiteral`This is a string with interpolated variables like ${someVar} and also ${otherVar}.`
Specifically, String.raw
is meant to be used as the tag of a template literal, and it will return the raw string without processing any escaped characters. Meaning n
will remain as n
and not become a newline, t
will remain as t
and not become a tab, etc. It does this by automatically adding slashes before any escaping slashes, thereby escaping them, so it's equivalent to using \n
, \t
, etc.
So in your case, if you want to use that method, since you can't put template literals directly in an object key declaration (it doesn't parse correctly), you'd do something like this:
var Array_QA = {};
Array_QA[String.raw`Large {lim_{x to 2}} (5^x + 2^x + 4)`] = "33";
Array_QA[String.raw`Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}`] = "0";
That said, having complex strings like that as object keys is probably not a good idea from the start... but it should work. I'd suggest refactoring your code to do that differently, if you can.
String.raw
is used with template literals, the new(ish) ES6 syntax for strings with interpolated variables, embedded quotes and newlines, and the optional application of "tags" (which are just function callbacks that receive the pieces of the template split up by each interpolated variable to return the final combined string however you like).
So if I have a function that processes a template literal, and it's called processLiteral
, then I could do something like this to apply it to a literal:
processLiteral`This is a string with interpolated variables like ${someVar} and also ${otherVar}.`
Specifically, String.raw
is meant to be used as the tag of a template literal, and it will return the raw string without processing any escaped characters. Meaning n
will remain as n
and not become a newline, t
will remain as t
and not become a tab, etc. It does this by automatically adding slashes before any escaping slashes, thereby escaping them, so it's equivalent to using \n
, \t
, etc.
So in your case, if you want to use that method, since you can't put template literals directly in an object key declaration (it doesn't parse correctly), you'd do something like this:
var Array_QA = {};
Array_QA[String.raw`Large {lim_{x to 2}} (5^x + 2^x + 4)`] = "33";
Array_QA[String.raw`Large {lim_{x to 2}} frac {x^2 - 6x + 8}{x^3 - 4}`] = "0";
That said, having complex strings like that as object keys is probably not a good idea from the start... but it should work. I'd suggest refactoring your code to do that differently, if you can.
answered Jan 7 at 20:20
IceMetalPunkIceMetalPunk
1,034816
1,034816
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
add a comment |
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
1
1
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
You could use them in computed property keys.
– Bergi
Jan 7 at 20:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038669%2fhow-to-use-string-raw-on-array-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown