Created
August 16, 2022 04:36
-
-
Save neilkuan/158c149cdcb148f50606c76f02cbbf23 to your computer and use it in GitHub Desktop.
Revisions
-
neilkuan revised this gist
Aug 16, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ const accountId2 = Object.keys(sts).filter( array => sts[array] === '12345678901 // find the key when value equal '123456789012'; let accountId: string[] = []; Object.entries(sts).forEach( array => array[1] == '123456789012' ? accountId.push(array[0]) : false); console.log(accountId2); console.log('*'.repeat(50)); -
neilkuan created this gist
Aug 16, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ interface stsInterface { [index: string]: string } const sts: stsInterface = { UserId: "AAAAAanbc:botocore-session", Account: "123456789012", Arn: "arn:aws:sts::123456789012:assumed-role/abc", Account1: "123456789012", Account2: "123456789012", Account3: "123456789012", } // find the key when value equal '123456789012'; // filter() will return Array back. // => not give "{}" will return value. const accountId2 = Object.keys(sts).filter( array => sts[array] === '123456789012'); // find the key when value equal '123456789012'; let accountId: string[] = []; Object.entries(sts).forEach( array => array[1] == '1234567890123' ? accountId.push(array[0]) : false); console.log(accountId2); console.log('*'.repeat(50)); console.log(accountId); //[ 'Account', 'Account1', 'Account2', 'Account3' ] //************************************************** //[ 'Account', 'Account1', 'Account2', 'Account3' ] // console.log(Object.entries(sts)) //[ // [ 'UserId', 'AAAAAanbc:botocore-session' ], // [ 'Account', '123456789012' ], // [ // 'Arn', // 'arn:aws:sts::123456789012:assumed-role/abc' // ], // [ 'Account1', '123456789012' ], // [ 'Account2', '123456789012' ], // [ 'Account3', '123456789012' ] //]