简体   繁体   中英

A comparaison between 2 equal variables returns false in Google script (sheets)

I hope you can help me in this mind blowing problem I have:

Well, I have 2 different arrays (cam and existentes). The [2] value of existentes is the same string than the 1 value of cam. But when I try to compare existentes [2] == cam [1] it returns a False.

在此处输入图像描述

Solution:

You are comparing two arrays : [Remarketing] == [Remarketing] while you should be comparing two strings Remarketing == Remarketing :

existentes[2][0]==cam[1][0]

Minimal Reproducible Example:

 const ar1 = ["Remarketing"]; const ar2 = ["Remarketing"]; console.log(ar1==ar2); // returns false console.log(ar1[0]==ar2[0]); // returns true

In case you had arrays with multiple elements you wanted to compare, then you can read this post on how to compare two arrays in JavaScript :

How to compare arrays in JavaScript?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM