Home > Mobile >  compare specific values from objects with different keys Javascript
compare specific values from objects with different keys Javascript

Time:05-07

This is a silly question, but nothing I try works. I have two objects nft and web3.givenProvider. Both contain an address as "0x0000000000000", but they are under separate keys. nft is under .seller and web3 is under .selectedAddress. Whenever I try to compare them using _.isEqual or toString it returns false even though the values are correct. I am not sure what I am missing here. I have even tried converting to an array and trying to _.find the address in the array, but that returned false.

// removed question mark
console.log(nft.seller === web3.givenProvider.selectedAddress))

NFT console.log() NFT console.log

Web3 console.log() Web3 console.log

CodePudding user response:

They dont equate to each other because NFT has upper case letters while Web3 has all its letters on lowercase. If both values should be case insensitive, convert both to the same case (lower/upper) then compare them.

Sample:

console.log(nft.seller.toLowerCase() === web3.givenProvider.selectedAddress.toLowerCase())
  • Related