首页 > 解决方案 > 将包含数字保留关键字的数组 t 字符串化

问题描述

我有一个数组,其中包含许多关键字和各种我想用 IDE 将其更改为字符串而不出错的东西是错误的。

 const history = ["Nearly four thousand years ago, in the Sumerian town of Ur in the valley
                 of the river Euphrates, lived a young man named Abraham. The people of
                 Ur had once worshipped Allah but as time passed they forgot the true
                 religion and started praying to idols, statues made of wood or clay and
                 sometimes even of precious stones. Even as a small child Abraham could
                 not understand how his people, and especially his father, could make
                 these images with their own hands, call them gods, and then worship
                 them. He had always refused to join his people when they paid respect to
                 these statues. Instead he would leave the town and sit alone, thinking
                 about the heavens and the world about him. He was sure his people were
                 doing wrong and so alone he searched for the right way. One clear night
                 as he sat staring at the sky he saw a beautiful shining star, so beautiful
                 that he cried out: „This must be Allah!' He looked at it in awe for some
                 time, until suddenly it began to fade and then it disappeared. He turned
                 away in disappointment saying: I love not things that set. (Qur'an 6.77)
                 On another night Abraham was again looking at the sky and he saw
                 the rising moon, so big and bright that he felt he could almost touch it. He
                 thought to himself: This is my Lord. (Qur'an 6.78) But it was not long
                 before the moon set as well. Then he said, Unless my Lord guide me, I
                 surely shall become one of the folk who are astray. (Qur'an 6.78)
                 Abraham then saw the beauty and splendor of the sunrise and decided
                 that the sun must be the biggest and most powerful thing in the universe.
                 But for the third time he was wrong, for the sun set at the end of the day.
                 It was then that he realized that Allah is the Most Powerful, the Creator of
                 the stars, the moon, the sun, the earth and of all living things. Suddenly he
                 felt himself totally at peace, because he knew that he had found the Truth.
                 When he said unto his father and his folk: What do you worship? They
                 said: We worship idols, and are ever devoted to them. He said: Do they
                 hear you when you cry? Or do they benefit or harm you? They said: Nay,
                 but we found our fathers acting in this manner.
                 He said: See now that which you worship, You and your forefathers!
                 Lo! they are (all) an enemy to me, except the Lord of the Worlds. Who
                 created me, and He guides me, And Who feeds me and waters me. And
                 when I sicken, then He heals me. And Who causes me to die, then gives
                 me lift (again) And Who, I ardently hope, will forgive me my sin on the
                 Day of judgement. (Qur'an 26.70-82) 
                 The Life of the Prophet Muhammad (Peace and blessings of Allah "]


const history = ["Nearly four thousand years ago in the Sumerian town of Ur in the valley
                 

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^

        SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:1047:16)
at Module._compile (internal/modules/cjs/loader.js:1097:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47

标签: javascript

解决方案


因此,您希望有一个包含该文本的字符串,但是,您还希望包含多行。您将收到的错误将是因为双引号 (") 和单引号 (') 不会在多行上继续。如果您想将字符串包装在多行上,如上所示,您将需要使用反引号 ( `)通常它是转义下方和制表符上方的键。由于当前的缩进,您会发现在执行此操作时字符串中有一些额外的空间,但是您可以更改该部分的缩进或添加一些split()join()函数来删除多余的制表符和空格


推荐阅读