Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 映射对象的特定数组_Javascript_Html_Css_Reactjs - Fatal编程技术网

Javascript 映射对象的特定数组

Javascript 映射对象的特定数组,javascript,html,css,reactjs,Javascript,Html,Css,Reactjs,.filter返回一个新数组,而不是修改调用它的数组。那么这条线呢 props.list.cards.filter(list=>list.value\u int==one) 实际上什么都没做 相反,试试看 let-cardArray; 如果(道具列表卡){ cardArray=props.list.cards.filter(list=>list.value\u int==one) 控制台日志(道具列表卡) cardArray=cardArray.map((card)=>{return()})

.filter
返回一个新数组,而不是修改调用它的数组。那么这条线呢

props.list.cards.filter(list=>list.value\u int==one)
实际上什么都没做

相反,试试看

let-cardArray;
如果(道具列表卡){
cardArray=props.list.cards.filter(list=>list.value\u int==one)
控制台日志(道具列表卡)
cardArray=cardArray.map((card)=>{return()})
}
或者,由于映射和过滤器返回新数组,您也可以将它们链接在一起:

if(道具列表卡){
cardArray=props.list.cards
.filter(list=>list.value\u int==1)
.map((卡)=>{return()})
}

还有很多其他方法可以安排事情–重要的是使用
的结果。filter

你应该能够通过在
映射之前添加
切片
轻松完成这项工作。它看起来是这样的:

desc: "A youthful figure in the robe of a magician, having the countenance of divine Apollo, with smile of confidence and shining eyes. Above his head is the mysterious sign of the Holy Spirit, the sign of life, like an endless cord, forming the figure 8 in a horizontal position . About his waist is a serpent-cincture, the serpent appearing to devour its own tail. This is familiar to most as a conventional symbol of eternity, but here it indicates more especially the eternity of attainment in the spirit. In the Magician's right hand is a wand raised towards heaven, while the left hand is pointing to the earth. This dual sign is known in very high grades of the Instituted Mysteries; it shews the descent of grace, virtue and light, drawn from things above and derived to things below. The suggestion throughout is therefore the possession and communication of the Powers and Gifts of the Spirit. On the table in front of the Magician are the symbols of the four Tarot suits, signifying the elements of natural life, which lie like counters before the adept, and he adapts them as he wills. Beneath are roses and lilies, the flos campi and lilium convallium, changed into garden flowers, to shew the culture of aspiration. This card signifies the divine motive in man, reflecting God, the will in the liberation of its union with that which is above. It is also the unity of individual being on all planes, and in a very high sense it is thought, in the fixation thereof. With further reference to what I have called the sign of life and its connexion with the number 8, it may be remembered that Christian Gnosticism speaks of rebirth in Christ as a change "unto the Ogdoad." The mystic number is termed Jerusalem above, the Land flowing with Milk and Honey, the Holy Spirit and the Land of the Lord. According to Martinism, 8 is the number of Christ."
meaning_rev: "Physician, Magus, mental disease, disgrace, disquiet."
meaning_up: "Skill, diplomacy, address, subtlety; sickness, pain, loss, disaster, snares of enemies; self-confidence, will; the Querent, if male."
name: "The Magician"
name_short: "ar01"
type: "major"
value: "1"
value_int: 1
cardArray=props.list.cards.slice(0,2).map((card)=>{return()})
通过这种方式,您也可以卸下过滤器

编辑:您可以使用
过滤器以相同的方式进行编辑。正如Nicholas在回答中提到的,
slice
filter
都返回一个新数组,这是您最初的问题。无论使用哪一个,都必须通过附加它来映射这个新数组。根据数据集的大小,您可以阅读更多关于哪一个更适合使用的信息

desc: "A youthful figure in the robe of a magician, having the countenance of divine Apollo, with smile of confidence and shining eyes. Above his head is the mysterious sign of the Holy Spirit, the sign of life, like an endless cord, forming the figure 8 in a horizontal position . About his waist is a serpent-cincture, the serpent appearing to devour its own tail. This is familiar to most as a conventional symbol of eternity, but here it indicates more especially the eternity of attainment in the spirit. In the Magician's right hand is a wand raised towards heaven, while the left hand is pointing to the earth. This dual sign is known in very high grades of the Instituted Mysteries; it shews the descent of grace, virtue and light, drawn from things above and derived to things below. The suggestion throughout is therefore the possession and communication of the Powers and Gifts of the Spirit. On the table in front of the Magician are the symbols of the four Tarot suits, signifying the elements of natural life, which lie like counters before the adept, and he adapts them as he wills. Beneath are roses and lilies, the flos campi and lilium convallium, changed into garden flowers, to shew the culture of aspiration. This card signifies the divine motive in man, reflecting God, the will in the liberation of its union with that which is above. It is also the unity of individual being on all planes, and in a very high sense it is thought, in the fixation thereof. With further reference to what I have called the sign of life and its connexion with the number 8, it may be remembered that Christian Gnosticism speaks of rebirth in Christ as a change "unto the Ogdoad." The mystic number is termed Jerusalem above, the Land flowing with Milk and Honey, the Holy Spirit and the Land of the Lord. According to Martinism, 8 is the number of Christ."
meaning_rev: "Physician, Magus, mental disease, disgrace, disquiet."
meaning_up: "Skill, diplomacy, address, subtlety; sickness, pain, loss, disaster, snares of enemies; self-confidence, will; the Querent, if male."
name: "The Magician"
name_short: "ar01"
type: "major"
value: "1"
value_int: 1
cardArray = props.list.cards.slice(0, 2).map((card) =>{return (<ThreeCardMap value={card.value_int} name={card.name} meaningup={card.meaning_up} meaningdown={card.meaning_rev}/>)})