Return *any* party member that has a certain skill?

For an event, i wanted to save the ID of any party member that has a certain skill to a variable. However, it just sets it to "0".

Here's what I tried so far:

JavaScript:
$gameParty.members().forEach(function(actor) { if (actor.hasSkill(12)) { return actor; } } )
$gameParty.members().forEach(function(actor) { if (actor.hasSkill(12)) { return actor.actorId(); } } )
$gameParty.members().forEach(function(actor) { return actor.actorId() && actor.hasSkill(12); })

Neither of these sets the variable to anything above 0.
forEach() isn't the correct function to use for this. If you check the documentation for it, it doesn't actually return anything back to you - any return call is discarded.

All it's for is performing an operation upon each element of an array.

If you want to find something, there are a number of methods. One is, appropriately, find(). That returns the first element that matches your criterion, so you'd do:
Code:
$gameParty.members().find(actor => actor.hasSkill(12)).actorId()
(note I'm also trimming down how much you have to type by using arrow function notation)

If you care about knowing each party member that has the skill, filter() returns an array of everything that meets the criterion:
Code:
let skillUsers = $gameParty.members().filter(actor => actor.hasSkill(12));
forEach() isn't the correct function to use for this. If you check the documentation for it, it doesn't actually return anything back to you - any return call is discarded.

All it's for is performing an operation upon each element of an array.

If you want to find something, there are a number of methods. One is, appropriately, find(). That returns the first element that matches your criterion, so you'd do:
Code:
$gameParty.members().find(actor => actor.hasSkill(12)).actorId()
(note I'm also trimming down how much you have to type by using arrow function notation)

If you care about knowing each party member that has the skill, filter() returns an array of everything that meets the criterion:
Code:
let skillUsers = $gameParty.members().filter(actor => actor.hasSkill(12));
awesome, thanks man!!

Original thread: https://forums.rpgmakerweb.com/threads/return-any-party-member-that-has-a-certain-skill.161716/