Add a few more values ​to the previous array in postman - javascript

in my test i sholud compare response permission with my rolepermission_array variable in envirment
but there is diffrent , the reponse permission has 4 more permission because of it i should update my envirment
what should i do
First
in this image my response has 4 more value
Second
"authenticated",
"manage_profile",
"manage_account",
"verify_email"
i should add this values to rolepermission_array
i update my code but still get error
PreRequest
Test
Result

You can add element to array using push(element1, element2, ...)
To save array to environment, remember stringify
To get array from environment, use parse
In tab Test
const res = pm.response.json();
const per = res.data.permissions;
const rolepermission = JSON.parse(pm.environment.get("rolepermission_array"));
rolepermission.push("authenticated", "manage_profile", "manage_account", "verify_email");
pm.test("check permissions", () => {
pm.expect(per).eql(rolepermission);
})

Related

array different data inside a single array

how can I get all this array in one array without getting it one after the other like this in the code below? i mean saving the whole data inside one variable without giving a specific index of the array
here's the code
const favoriteProductone = data?.getAllLikeProduct[0]
const favoriteProductTwo = data?.getAllLikeProduct[1]
const favoriteProductThree = data?.getAllLikeProduct[2]
console.log(favoriteProductone?.Like[0])
console.log(favoriteProductTwo?.Like[0])
console.log(favoriteProductThree?.Like[0])
Just iterate the array like so:
if (!data) {
throw "data is falsy - there is nothing to process";
}
data.getAllLikeProduct.forEach(p => {
console.log(p.Like[0])
});

How do I achieve this using firebase 9 push?

I switch to firebase 9 and want to achieve following
customers
-MomOdRNzkqr9vDk_MmE:"ptwXJ7JRAASFgd3KoS2fQyQhyV613"
-Myb3b_2W-7FTlsZvXCO:"QZOQ43DGYwfu4djlZ5EjEVksOr53"
I am trying the following
const customerSelectedRef = ref(db,`/serviceProvider/${user1.uid}/moneyCollector/customers`);
const customerSelectedRefPush = push(customerSelectedRef);
set(customerSelectedRefPush, customerSelected); // not wanted to use {customerSelected} which gives key value pair under push id
How could add value directly to push id?
The old method was
firebase
.database()
.ref(`/serviceProvider/${user1.uid}/moneyCollector/customers`)
.push(customerSelected)
.then(() => {
console.log("Data set.moneyCollector cutomer added");
checkdubArray = [];
});
Where push id acts as key for customerSelected
and I try to get same result in firebase 9.
Dont want the result which I have marked as cross
You can pass the string value directly in push() along with the DatabaseReference as shown below:
const customerSelectedRef = ref(db,`/service/${user1.uid}/Collector/customers`);
await push(customerSelectedRef , "string_value") // Not object
The result would be:

Getting empty array in javascript using array.push() method

I am trying to push data into array in this code
let eyesData = [];
const pushFaceData = (
{ rightEyeOpenProbability },
i
) => {
//Value is getting printed in console but not getting pushed
//console.log(rightEyeOpenProbability);
eyesData.push(rightEyeOpenProbability);
};
const renderFaces = () => {
faces.map(pushFaceData);
};
console.log(eyesData);
faces is stream of data that updates itself in every 100ms so eyesData array should also be getting populated on each 100ms but in console, eyesData is always getting printed with empty value.
Array[]
Array[]
.
.
If rightEyeOpenProbability is printing to the console, then there is no reason your code should be failing...
You are probably changing eyesData somewhere. For example, if you made a typo when checking its length, you could be erasing it:
if( eyesData.length = 0 ) { ... } //this line would erase eyesData[]'s contents

Access nested object JSON array with Javascript

Using Logger.log(response.data.phone), I'm getting this in my log:
[{label=work, primary=true, value=5558675309}, {label=work, value=6108287680, primary=false}, {value=6105516373, label=work, primary=false}]
What I want is to return the two phone numbers as 5558675309, 6108287680.
I've tried Logger.log(response.data.phone.value) and that doesn't work. I've tried ...phone['value'], I've tried ...phone[0].value and this one does return the first phone number 5558675309. But I would like it to return all of the value values whenever I put in the phone key. So how would I modify the logger?
response.data.phone is an array you can try looping through it:
Logger.log(response.data.phone.map(phone => phone.value).join(', '));
const response = {data: {phone : [{label:'work', primary:true, value:5558675309}, {label:'work', value:6108287680, primary:false}, {value:6105516373, label:'work', primary:false}] } }
const Logger = { log : console.log};
Logger.log(response.data.phone.map(phone => phone.value).join(', '));
response.data is an array, response.data.phone does not exist. What you want is response.data[n].phone for an integer n. You can do this with a forEach loop.
response.data.forEach((element) => Logger.log(element.phone.value));
If for whatever reason you need support for older browsers you can use the older function syntax:
response.data.forEach(function(element){
Logger.log(element.phone.value)
});

How do I get the value from this API?

getCoinPrice(coinName: string) {
return this._http
.get(
`https://min-api.cryptocompare.com/data/pricemulti?fsyms=${coinName}&tsyms=EUR`
).pipe(map((result) => (result)));
JSON from the link with "BTC" as coinName is: {"BTC":{"EUR":8226.43}} and the method gives me back an observable.
How would I return the price value(8226.43) in a variable?
Try this code. Should just work fine for you.
getCoinPrice(coinName: string) {
return this._http
.get(
`https://min-api.cryptocompare.com/data/pricemulti?fsyms=${coinName}&tsyms=EUR`
).pipe(map((result) => (result.BTC.EUR)));
You can learn more about how to access objects and their value here https://www.w3schools.com/js/js_objects.asp
Here is the Javascript MDN explanation about how to work with objects: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
Working example:
This is to show how we will get the value you desired by accessing the objects with .
//Your results
var result = JSON.parse('{"BTC":{"EUR":8226.43}}');
//This will print out 8226.43
console.log(result.BTC.EUR)
You want result[coinName]["EUR"]
As per observable result you are getting {"BTC":{"EUR":8226.43}} for coinName BTC, you want to retrieve "8226.43" from it.
So,
coinName = 'BTC' & observableResult = {"BTC":{"EUR":8226.43}}
If you want to get the value based on coinName, you could use the below method since coinName is also the key (BTC) in the observableResult object.
observableResult[coinName] // This will result to {EUR: 8226.43}
So, observableResult[coinName].EUR will result to 8226.43

Categories