I am trying to append a single quote and also add double quote, but it shows an error as follows
[ts] ':' expected
"id": " + ' + jsonObject["school_id"] + ' + "
expected output would be something similar as follows
"id" : "'12345'"
I am trying to append a single quote and also add double quote, but it shows an error as follows
[ts] ':' expected
"id": " + ' + jsonObject["school_id"] + ' + "
expected output would be something similar as follows
"id" : "'12345'"
You can't just use ' like that.
If you want to include single quotes in the string, enclose them in a string.
const jsonObject = {"school_id": "12345"}
const obj = {"id": "'" + jsonObject["school_id"] + "'"}
console.log(obj);
You could use template strings to easily create it.
let jsonObject = {school_id:"1234"}
let s = `"id" : "'${jsonObject["school_id"]}'"`;
console.log(s)
You can simply use Template Strings:
const obj = { school_id: "1234" }
const str = `"id" : "'${obj["school_id"]}'"`;
I have not worked much with TypeScript, but looks like they are supported: https://basarat.gitbooks.io/typescript/docs/template-strings.html
please try this to achieve expected result "id" : "'12345'"
var jsonObject = {school_id: 12345}
var a = {"id": '\'' + jsonObject['school_id'] + '\''}
console.log (a)
var school_id = '12345';
school_id = "'"+school_id+"'";
school_id = '"'+school_id+'"';
console.log(school_id);
You can do like this but make sure you know the use before doing it. don't code blindly.