-2
Variables.PolicyCustomerAddresses

(3) [{…}, {…}, {…}]
0: {ADRES_EK: null, ADRES_ID1: 885843,  ADRES_TEXT: "XXXX", MUSTERI_ADRES_ID: "333", …}

1: {ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222", …}

2: {ADRES_EK: null, ADRES_ID1: 890902,  ADRES_TEXT: "ZZZZ", MUSTERI_ADRES_ID: "111", …}
length: 3

correspondenceAdress == 222

like this and i wanna take line who MUSTERI_ADRES_ID == 222 by linq

var adreeess = Variables.PolicyCustomerAddresses;
                var adrx = Enumerable.From(adreeess)
                        .Where("$.MUSTERI_ADRES_ID === correspondenceAdress ")
                        .FirstOrDefault(null)
                        .First();
Eddie
  • 26,593
  • 6
  • 36
  • 58
Joe
  • 23
  • 8
  • You can use [`find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) like this: `Variables.PolicyCustomerAddresses.find(a => a.MUSTERI_ADRES_ID == correspondenceAdress)` – adiga Apr 12 '19 at 09:36
  • 1
    what about the [question](https://stackoverflow.com/q/55626262/1447675) from yesterday? – Nina Scholz Apr 12 '19 at 09:36
  • Linq.js is redundant by the way. You can use [Array.prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype#Methods) methods to do all these operatiosn – adiga Apr 12 '19 at 09:39

1 Answers1

1

MUSTERI_ADRES_ID has to be a string, as the value in the given data.

var Variables = { PolicyCustomerAddresses: [{ ADRES_EK: null, ADRES_ID1: 885843,  ADRES_TEXT: "XXXX", MUSTERI_ADRES_ID: "333" }, { ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222" }, { ADRES_EK: null, ADRES_ID1: 890902,  ADRES_TEXT: "ZZZZ", MUSTERI_ADRES_ID: "111" }] },
    correspondenceAdress = "222", // string!
    result = Enumerable.From(Variables.PolicyCustomerAddresses)
        .Where("$.MUSTERI_ADRES_ID === correspondenceAdress")
        .DefaultIfEmpty(null)
        .First();

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.js"></script>
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
  • i get this error "Uncaught ReferenceError: correspondenceAdress is not defined" – Joe Apr 12 '19 at 09:58
  • then you have to look `correspondenceAdress` where you have used it the first time and declare it. – Nina Scholz Apr 12 '19 at 10:00
  • i get it from another function it is a parameter – Joe Apr 12 '19 at 10:08
  • maybe it's wrong spelling or lower/upper case mismatch. – Nina Scholz Apr 12 '19 at 10:11
  • im not get any error .Where("$.MUSTERI_ADRES_ID === $.correspondenceAdress") with this. but result is (3) [{…}, {…}, {…}] 0: {ADRES_EK: null, ADRES_ID1: 885843, ADRES_TEXT: "XXXX", MUSTERI_ADRES_ID: "333", …} 1: {ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222", …} 2: {ADRES_EK: null, ADRES_ID1: 890902, ADRES_TEXT: "ZZZZ", MUSTERI_ADRES_ID: "111", …} length: 3 turn again same values – Joe Apr 12 '19 at 10:16
  • i have no idea, what you mean. – Nina Scholz Apr 12 '19 at 10:18
  • im not get any error .Where("$.MUSTERI_ADRES_ID === $.correspondenceAdress") is running not give me any error but console.log(result); result is include all list again not give me only {ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222", …} line – Joe Apr 12 '19 at 10:20
  • then you have a console, problem, which is having a time warp, which is a known problem, like https://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays – Nina Scholz Apr 12 '19 at 10:22