使用包括与数组的React
我已经在React中进行了一些Apollo查询,并且我正在尝试运行AN INCALE BEACK对其进行检查。但是,它总是在控制台日志中出现错误。这是我的代码:
const onSubmit = (data: any) => {
console.log (data1)
console.log(data2)
console.log(data2.item)
console.log([data1].includes(data2.item))}
这是输出:
console.log(data1): Test Array(2)
0: {Name: 'TEST', item: 'Crayons'}
1: {Name: 'TEST', item: 'Taco'}
console.log(data2) : {Name: 'Jack', place: 'Home', item: 'Taco'}
console.log(data2.item) : Taco
console.log([data1].includes(data2.item)) : False
我正在寻找第二列“项目”的输出,其中炸玉米饼匹配以正确。
我还尝试通过Data1.Item [1] .Item访问,但仍然返回一个错误。
可能是因为类型是对象?
是否有一种简单的方法来检查Data1的整个第二列? (物品)。列表只会变得更大
I've done a few apollo queries in react and I'm trying to run an includes check against them. It however it always comes up false in the console log. Here's my code:
const onSubmit = (data: any) => {
console.log (data1)
console.log(data2)
console.log(data2.item)
console.log([data1].includes(data2.item))}
and here's the output:
console.log(data1): Test Array(2)
0: {Name: 'TEST', item: 'Crayons'}
1: {Name: 'TEST', item: 'Taco'}
console.log(data2) : {Name: 'Jack', place: 'Home', item: 'Taco'}
console.log(data2.item) : Taco
console.log([data1].includes(data2.item)) : False
I'm looking for the output of that second column 'item' where taco matches to come up as true.
I've also tried accessing by data1.item[1].item but it still returned a false.
It may be because the type is an object?
Is there a simple way to check the entire second column of data1? (item). The list only gets bigger
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Include Will Will检查以查看对象是否通过参考值相同。您可以通过使用
一些
检查条目的项目是否匹配。Include will check to see if the objects are the same by reference value. You can check if an entry's item is matching by using
some
.